Import a MySQL Database
Before you import a MySQL® backup, you can create a .my.cnf file with the root credentials. This file enables you to avoid having to input the password when you restore the databases and also helps if you want to create a cron job script to backup MySQL daily.
Store your MySQL root password in /root/.my.cnf, as shown in the following example, and use chmod 600
to set appropriate permisssions for the file.
[client]
user=root
password=yourmysqlrootpassword
Restore commands
Use the following command to restore a single database:
$ mysql [database_name] < /path/to/backup/backupfile.sql
Use the following command to restore all databases. The tables need to exist, or backup needs to contain CREATE TABLE statements:
$ mysql < /path/to/backup/alldatabases.sql
Updated 12 months ago