linux下mysql的备份和还原

1.备份:

[root@localhost ~]# mysqldump -u root -p test>/opt/test.sql
Enter password: 

使用mysqldump备份, 并将备份文件指向输出目录, 输入密码即可

2.还原:

先创建要还原的数据库

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 8
Server version: 5.0.45 Source distribution

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| mysql              | 
+--------------------+
2 rows in set (0.00 sec)

mysql> create database test;
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye

指向备份文件进行还原

[root@localhost ~]# mysql -u root -p test</opt/test.sql 
Enter password:
原文地址:https://www.cnblogs.com/leaf1117/p/3466945.html