MySQL/MariaDBDatabase Backup與恢複之mysqlpump入門操作

來源:互聯網
上載者:User

標籤:

建立測試用表:
MariaDB [music]>  create table summary(id int,info char(128));
Query OK, 0 rows affected (0.05 sec)

MariaDB [music]> show tables;
+-----------------+
| Tables_in_music |
+-----------------+
| summary         |
| test            |
+-----------------+
2 rows in set (0.00 sec)

插入測試資料:
MariaDB [music]> insert into summary values(1,‘Eric Gao is a Oracle DBA‘);
Query OK, 1 row affected (0.00 sec)

MariaDB [music]> insert into summary values(2,‘Eric Gao is a MySQL DBA‘); 
Query OK, 1 row affected (0.05 sec)

MariaDB [music]> insert into summary values(3,‘Eric Gao is a AIX  SA‘); 
Query OK, 1 row affected (0.00 sec)

MariaDB [music]> insert into summary values(4,‘Eric Gao is a Linux  SA‘); 
Query OK, 1 row affected (0.01 sec)

MariaDB [music]> select * from summary;
+------+--------------------------+
| id   | info                     |
+------+--------------------------+
|    1 | Eric Gao is a Oracle DBA |
|    2 | Eric Gao is a MySQL DBA  |
|    3 | Eric Gao is a AIX  SA    |
|    4 | Eric Gao is a Linux  SA  |
+------+--------------------------+
4 rows in set (0.00 sec)

執行mysqldump備份:
[[email protected] ~]# mysqldump -u root --databases music --lock-all-tables --flush-logs > /tmp/music.sql
[[email protected] ~]# cd /tmp
[[email protected] tmp]# ls -lt
total 86744
-rw-r--r--. 1 root root     1948 Mar  4 05:58 music.sql


刪除資料庫,已驗證稍後還原效果:
MariaDB [(none)]> drop database music;
Query OK, 2 rows affected (0.03 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

可以看到music資料庫已經不在了。


還原整庫:
MariaDB [(none)]> source /tmp/music.sql
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Database changed
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 4 rows affected (0.01 sec)
Records: 4  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

MariaDB [music]> 

驗證資料是否已找回:
MariaDB [music]> select * from summary;
+------+--------------------------+
| id   | info                     |
+------+--------------------------+
|    1 | Eric Gao is a Oracle DBA |
|    2 | Eric Gao is a MySQL DBA  |
|    3 | Eric Gao is a AIX  SA    |
|    4 | Eric Gao is a Linux  SA  |
+------+--------------------------+
4 rows in set (0.00 sec)

OK,資料已還原!~~~

MySQL/MariaDBDatabase Backup與恢複之mysqlpump入門操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.