Thứ Tư, 24 tháng 7, 2013

export and import MYSQL database from command line

Sometimes you may need to export and import mysql database from command line. This might be useful when you are working with large database.
Export database from MYSQL:
Syntax:
#mysqldump -u database_user_name -p  database-name >  destination-dir/desire-name.sql
1.  After -u put your database user name
2.  -p is for database password option
3.  After running this command it will ask for the database password, so you need to put the database password and press enter
Example:
#mysqldump -u root -p  my_db >  /home/mhabub/my_db_backup.sql
The above example will dump my_db into /home/mhabub with name my_db_backup.sql
Here I am using mysql root account to dump the database, so after -u i have written root
Importing database into a MYSQL:
Syntax:
#mysql -u database_user_name  -p my_db < /home/mhabub/my_db_backup.sql
1. Here also its same as export. after -u put your database user name and -p is used for password option
Example:
#mysql -u root -p my_db < /home/mhabub/my_db_backup.sql
Here I am importing my_db_backup.sql script into the database my_db

Không có nhận xét nào:

Đăng nhận xét

Học lập trình web căn bản với PHP

Bài 1: Các kiến thức căn bản Part 1:  https://jimmyvan88.blogspot.com/2012/05/can-ban-lap-trinh-web-voi-php-bai-1-cac.html Part 2:  https://...