1. Use mysqldump tool to backup
1.1 Detailed explanation of mysqldump command:
Common parameters:
-u 登录的用户,默认使用root
-p 登录密码,默认为空密码
-h MySQL服务器的IP地址(默认连接localhost)
-P MySQL连接端口(默认为3306)
-A 全备,备份所有的数据库
-B 备份指定的库
1.2 Full equipment:
1.2.1 Command format:
mysqldump -u用户 -p密码 -A > 备份的路径
1.2.2 Examples
Back up all databases in MySQL to the /home/database_backup directory
创建备份目录
mkdir /home/db_back
全备
mysqldump -u用户 -p密码 -A > /home/db_back/all.sql
1.3 Backup multiple databases
1.3.1 Command format:
mysqldump -u用户 -p密码 -B 要备份的数据库 > 备份的路径
1.3.2 Examples
Back up the baidu, jingdong, and alibaba databases in MySQL to the /home/database_backup directory
mysqldump -uroot -p456 -B baidu jingdong alibaba > /home/db_back/bja.sql
1.4 Backup table: backup dupan table under baidu library
1.4.1 Command format:
mysqldump -u用户 -p密码 库名 表名 > 备份的路径
1.3.2 Examples
Back up the dupan table under the baidu database in MySQL to the /home/database_backup directory
mysqldump -uroot -p456 baidu dupan > /home/db_back/dupan.sql
1.5 Restore data
1.5.1 mysql command recovery
Restore the specified database
mysql -uroot -p456 < /home/db_back/baidu.sql
Restore the specified table under the specified database, when restoring the table, you must specify the database to be restored
mysql -uroot -p456 baidu < /home/db_back/dupan.sql
1.5.2 source statement recovery
Restore all databases
MariaDB [(none)]> source /home/db_back/all.sql;
Restore the specified table under the specified data
MariaDB [test]> use baidu;
Database changed
MariaDB [baidu]> source /home/db_back/dupan.sql;