Import a MySQL Database
Last updated on: 2020-04-02
Authored by: James Andrade
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
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