您现在的位置是:课程教程文章

mysql如何对数据库进行恢复

2023-12-14 20:28课程教程文章 人已围观

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

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

[root@localhost~]#mysql-uroot-ptest<mysql-user.sql
Enterpassword:
[root@localhost~]#mysql-uroot-p
Enterpassword:
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis17
Serverversion:5.5.22-logSourcedistribution

Copyright(c)2000,2011,Oracleand/oritsaffiliates.Allrightsreserved.

OracleisaregisteredtrademarkofOracleCorporationand/orits
affiliates.Othernamesmaybetrademarksoftheirrespective
owners.

Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.

mysql>usetest;##验证导入结果
Databasechanged
mysql>showtables;
+----------------+
|Tables_in_test|
+----------------+
|user|
+----------------+
1rowinset(0.00sec)

mysql>

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

[root@localhost~]#cd/usr/local/mysql/data/
[root@localhostdata]#ls
authib_logfile0localhost.errmongodbmysql-bin.000001mysql-bin.000003mysql-bin.indexperformance_schema
ibdata1ib_logfile1localhost.pidmysqlmysql-bin.000002mysql-bin.000004mysql.error.logtest
[root@localhostdata]#mvauth/tmp/##移动auth库,进行模拟故障操作。
[root@localhostdata]#ls-ldauth
ls:无法访问auth:没有那个文件或目录
[root@localhostdata]#mysql-uroot-p<~/auth.sql##执行导入恢复操作。
Enterpassword:
ERROR1050(42S01)atline63:Table'`auth`.`users`'alreadyexists
[root@localhostdata]#ls-ldauth##确认恢复后的结果。
drwx------.2mysqlmysql40968月105:17auth
[root@localhostdata]#

以上就是mysql对数据库进行恢复,希望对大家有所帮助。更多mysql学习指路:MySQL

推荐操作系统:windows7系统、mysql5.8、DELL G3电脑

课程教程:mysql如何对数据库进行恢复

上一篇:python线程中Condition的原理

下一篇:没有了

站点信息

  • 文章统计篇文章