MySQL database backup and restore
Chapter 1: Import and Export of Database
① Export of database
Need to use the mysqldump program, in the bin folder under the mysql installation path . In which path cd executes the command, the last sql backup file is generated there.
"/usr/local/mysql-8.0.11/bin/mysqldump" -uroot -p ncc_0807mysql > ncc_0807mysql.sql
[root@localhost ~]# cd /usr/local/mysql-8.0.11/
[root@localhost mysql-8.0.11]# "/usr/local/mysql-8.0.11/bin/mysqldump" -uroot -p ncc_0807mysql > ncc_0807mysql.sql
Enter password:
After entering the password, you can start importing the library without reporting an error, and you will pop out after you finish importing the library.
[root@localhost mysql-8.0.11]#
② Export optimization of mysqldump under large data volume
mysql database export optimization
If the amount of data is large, the export may take several hours. If we optimize it a little, it will be much faster.
First query the two values through the following statement.
show variables like 'max_allowed_packet';
show variables like 'net_buffer_length';
The optimized sql statement is as follows, which is to add two parameters to the back and bring the value we found out.
"/usr/local/mysql-8.0.11/bin/mysqldump" -uroot -p ncc_0807mysql > ncc_0807mysql.sql --max_allowed_packet=67108864 --net_buffer_length=16384
The effect diagram after generation is as follows, you can see that the backup file is generated in the location of my cd .
③ Export of database
Import the database with the mysql command.
"/usr/local/mysql-8.0.11/bin/mysql" -uroot -p ncc_0901mysql < ncc_0807mysql.sql
Just wait for the execution to complete.
[root@localhost ~]# cd /usr/local/mysql-8.0.11/
[root@localhost mysql-8.0.11]# "/usr/local/mysql-8.0.11/bin/mysql" -uroot -p ncc_0901mysql < ncc_0807mysql.sql
Enter password:
Like it if you like it ❤!