Export A MySQL Database
Sometimes you may need to import and export your MySQL databse from command line. Then this maybe could help you out.
#mysqldump -u database_user_name -p database-name > dbname.sql
- Behind -u you should put your database user name
- -p this is for the database password option
- When you have done this command it will ask for the database password, so you put the password in and press enter.
#mysqldump -u root -p my_db > /home/kudda/my_db_backup.sql
- The example above will dump my_db into /home/kudda and it will land under the name of my_db_backup.sql. Also i am using mysql root to easily dump database, so when i written -u after that you shall write root.
Import A MySQL Database
Here it should be almost the same as the export.
#mysql -u database_user_name -p my_db < /home/kudda/my_db_backup.sql
- Here it is the same as export. after u- you put your database user name and the -p is used for the pasword option still.
- Here is one example of it.
Example: mysql -u root -p my_db < /home/kudda/my_db_backup.sql
- On the example above i am importing my_db_backup.sql script into the database my_db