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
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
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