• 技术文章 >数据库 >MySQL

    mysql如何对数据库进行恢复

    小妮浅浅小妮浅浅2021-08-23 09:54:30原创4909

    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学习指路:MySQL

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

    专题推荐:mysql 数据库 恢复
    品易云
    上一篇:mysql查看备份文件的方法 下一篇:mysql常用的查看命令

    相关文章推荐

    • mysql表中插入数据的两种方法• mysql查看表结构的两种方法• mysql页的概念分析• mysql架构的组成• mysql char和varchar的比较• mysql InnoDB索引的使用注意• mysql死锁的检测• mysql有哪些分区类型• mysql水平分割有哪些方法• mysql分库是什么• mysql如何导出数据库• mysql查看备份文件的方法

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网