MySql Commands on LINUX

Different types of Useful mysql commands that are used to access mysql  services on linux machine  .

1. Login to mysql root user

#mysql –u root –p


#mysql -u root -h -p

2. Create new database


3. Provide privilegesto the database and users

>GRANT ALL ON DUMPDB.* TO user1@localhost IDENTIFIED BY ‘root’;

>mysql -u user1 –p


4. To change mysql user password:

>SET PASSWORD FOR ‘user name’@’localhost’ = PASSWORD(‘root’);



5. To login without password

#mysql -u $MYSQL_ROOT -p $MYSQL_PASS -h

Create the .my.cnf and add

#vi  ~/my.cnf/


Provide authentication

#chmod 0600  /etc/my.cnf

6. Forgot password recovery

When you have forgot your password, you can recover it by typing the below commands.

#/etc/init.d/mysqld stop

#mysqld_safe –skip-grant-tables &

#mysql –u root

>use mysql;

>update user set password=PASSWORD(“password”) where User=’root’;

>flush privileges;


#/etc/init.d/mysqld restart

Leave a Reply

Your email address will not be published. Required fields are marked *

17 − 9 =