溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql怎么對數(shù)據(jù)庫進行恢復

發(fā)布時間:2021-06-25 09:12:04 來源:億速云 閱讀:153 作者:小新 欄目:編程語言

小編給大家分享一下mysql怎么對數(shù)據(jù)庫進行恢復,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

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           ## 執(zhí)行導入恢復操作。
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怎么對數(shù)據(jù)庫進行恢復”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI