PDA

View Full Version : MySQL Commands



James007
03-18-2009, 07:43 PM
Some Useful MySQL commands are as follows ::

To enter the mysql from root :

# mysql

Note: This will only works when root password and mysqladmin (mysql root) password is same, if passwords are different use following command.

#mysql -u root -p password

To see all databases :

mysql>show databases;

To change the database :

mysql>use database name;

To see the tables under the database :

mysql>show tables;

To see the perticular table details :

mysql>select * from table;

Ex. select * from phplist_admin;

To restore the database backup from .sql file :

#mysql -u usename -p password databasename < .sql file

Ex. mysql -u data_base1 -pe460v9OZ8zfH data_base1 < plst.sql

To see the current running mysql process :

#mysqladmin processlist or #mysqladmin proc stat

To take the backup of mysql database :

mysqldump --opt db_name > backup-file.sql

(opt = Options)

Ex. mysqldump --opt data_base1 > plst1.sql

You can read the dump file back into the server like this :

#mysql db_name < backup-file.sql

Ex. mysql data_base1 < plst1.sql

Or like this:

#mysql -e "source /path-to-backup/backup-file.sql" db_name

Enjoy:);):cool: