MySQL backup and recovery under Linux
Backup:
For example, we want to back up a database named Linux that already exists in MySQL, using the command mysqldump
The command format is as follows:
[Email protected] root]# mysqldump-u root-p linux >/root/linux.sql
Enter Password: Enter the password for the database here
Through the above command, we have to understand two things, first back up the database is to be a database administrator backup, second: The backup destination is/root, the backup file name is Linux.sql. In fact, the location and file name of the backup, according to their own situation to decide. Filenames can be taken by themselves, the path can be arranged by themselves;
For example, I want to back up the Linux database to/home/beinan, the database file name is Linuxsir031130.sql, so you should enter the following command.
[Email protected] root]#mysqldump-u root-p linux >/home/beinan/linuxsir031130.sql
Enter Password: Enter the database password for the database administrator root here
V
If the data volume conference takes up a lot of space, you can use gzip to compress the data, with the following command:
#Mysqldump-u root-p TM | gzip > Tm_050519.sql.gz
So we can find the backup file of MySQL database named Linux in the/home/beinan directory Linuxsir031130.sql
Recovery:
First of all, we have to work on a few processes, such as adding a database administrator (if you haven't added a MySQL database administrator), creating a database, and so on.
For example, we want to/home/beinan this directory in the Linuxsir031130.sql this backup, import the database named Linux, should be the following operation;
[Email protected] root]#mysql-u root-p Linux
Enter Password: Enter the password here
backup and restore of MySQL under Windows ( prerequisites to ensure that the MySQL server is open )
Backup:
The first method: can be directly exported with Navicat
The second method: (1) Open the console cmd and make sure that the MySQL server can be connected successfully (2) switch to the MySQL Bin directory: cd C:\Program Files (x86) \mysql\mysql Server 5.5\bin (3) Mysqldump--user=root-p Database name > d:a.sql (Backup Database location and name), enter password to save successfully
The third method: Save the MySQL bak file, just add the last output name plus a bak
Recovery:
Method one is reversed from backup: Direct import via Navicat
The second method is reversed with the second of the backup: Just change the third step to the following:MySQL--user=root-p database name < D:a.sql (Backup database location and name), enter the password to successfully save
Access database use TEST3;
Then import the source d:/test3.sql with the instructions
Backup and Recovery for MySQL