Tuesday, October 20, 2020

Mysql Commands

Install Mysql In Ubuntu

sudo apt-get install mysql-server

Manage Mysql Service's by following commands

sudo service mysql status
sudo service mysql start
sudo service mysql stop
sudo service mysql restart

Connect locally MySQL server

mysql -u root -p   

Connect remotely MySQL server

 mysql -u user_name -h server_ip -p   

To set up mysql user password for the first time

mysql> SET PASSWORD for 'root'@'localhost' = PASSWORD('123456');

For mysql version 8

set password for 'root'@'%' = 'India@123';

For mysql version 8

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'India@123';

 

 

Mysql commands

show databases;
use databas es_name;
show tables;

DROP database database_name;
CREATE database database_name;
CREATE table table_name;

Mysql dump

mysqdump -u root -p database_name > database.sql


Mysql dump restore

mysql -u root -p database_name < database.sql


Show table data

select * from table_name;

Show table creted format

describe table_name;

Create mysql user account

CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'user_password';

Delete mysql user account

drop user 'user_name'@'localhost';                                    

Give_permission_for_single_DataBase

GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'localhost'; 

Give_permission_for_all_DataBase

GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'localhost';   

Reload the PRIVILEGES table

FLUSH PRIVILEGES                                                      

Show table data

select * from table_name;

Insert value in table

insert into  test2 (firstname) values ('subhash');

Repair database

sudo mysqlcheck -u admin -p --auto-repair --check --all-databases











No comments:

Post a Comment

testing