10.5数据库的备份及恢复

1.mysqldump命令用于备份数据库数据,格式为“mysqldump [参数] [数据库名称]”。

[root@dsrw ~]# mysqldump -u root -p dsrw > /root/dsrwDB.dump
Enter password: 
[root@dsrw ~]# mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 27
Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW databases;
+--------------------+
| Database           |
+--------------------+
| dsrw               |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.000 sec)

MariaDB [(none)]> DROP DATABASE dsrw;
Query OK, 1 row affected (0.005 sec)

MariaDB [(none)]> SHOW databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.000 sec)

2.恢复数据库

MariaDB [(none)]> CREATE DATABASE dsrw;
Query OK, 1 row affected (0.001 sec)
[root@dsrw ~]# mysql -u root -p dsrw < /root/dsrwDB.dump
Enter password: 
[root@dsrw ~]# mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 34
Server version: 10.3.11-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> USE dsrw;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [dsrw]> SHOW tables;
+----------------+
| Tables_in_dsrw |
+----------------+
| mybook         |
+----------------+
1 row in set (0.000 sec)
© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称

    请登录后查看评论内容