资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

mysql怎么对数据库进行恢复

小编给大家分享一下MySQL怎么对数据库进行恢复,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

吉安网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站设计等网站项目制作,到程序开发,运营维护。成都创新互联公司公司2013年成立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司

1、备份文件中只包含表的备份,不包含库的语句时,导入时必须指定库名,目标库必须存在。

可以从备份文件mysql-user.sql引入test库。

[root@localhost ~]# mysql -u root -p test < mysql-user.sql
Enter password:
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.5.22-log Source distribution
 
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> use test;                                   ## 验证导入结果
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| user           |
+----------------+
1 row in set (0.00 sec)
 
mysql>

2、如果备份文件包含完整的库信息,则在进行导入操作时不需要指定库名,可以从备份文件auth.sql恢复auth库。

[root@localhost ~]# cd /usr/local/mysql/data/
[root@localhost data]# ls
auth     ib_logfile0  localhost.err  MongoDB  mysql-bin.000001  mysql-bin.000003  mysql-bin.index  performance_schema
ibdata1  ib_logfile1  localhost.pid  mysql    mysql-bin.000002  mysql-bin.000004  mysql.error.log  test
[root@localhost data]# mv auth /tmp/                           ## 移动 auth 库,进行模拟故障操作。
[root@localhost data]# ls -ld auth
ls: 无法访问auth: 没有那个文件或目录
[root@localhost data]# mysql -u root -p < ~/auth.sql           ## 执行导入恢复操作。
Enter password:
ERROR 1050 (42S01) at line 63: Table '`auth`.`users`' already exists
[root@localhost data]# ls -ld auth                             ## 确认恢复后的结果。
drwx------. 2 mysql mysql 4096 8月   1 05:17 auth
[root@localhost data]#

以上是“mysql怎么对数据库进行恢复”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


分享标题:mysql怎么对数据库进行恢复
网页网址:http://cdkjz.cn/article/ggihds.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220