成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

轉戰MySQL Shell!數據庫備份新姿勢,輕松搞定備份操作!

數據庫 MySQL
MySQL8.0后續版本中主推使用MySQL Shell進行相關日常管理及維護操作,如果后續移除了MySQLdump等命令后,如何進行數據庫備份等相關操作呢?本文開始進行數據庫備份的操作。

一、MySQL Shell 安裝

1、下載 

可以在MySQL官網進行下載,地址https://dev.mysql.com/downloads/shell/。

需要根據操作系統類型、版本及glibc版本選擇對應的文件下載,例如:

[root@VM-4-14-centos ~]# uname  -a 
Linux VM-4-14-centos 3.10.0-1160.99.1.el7.x86_64 #1 SMP Wed Sep 13 14:19:20 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
[root@VM-4-14-centos ~]# ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

圖片

因此可以選擇如下版本下載。

圖片

2、部署

上傳文件至目標目錄后解壓文件。

解壓后建議配置軟鏈接。

tar -zxvf mysql-shell-8.0.35-linux-glibc2.17-x86-64bit.tar.gz

可以看到對應的工具了。

ln -s mysql-shell-8.0.35-linux-glibc2.17-x86-64bit mysql-shell

建議再配置一下環境變量。

將“/usr/local/mysql-shell/bin"追加至/etc/profile中。

在其他位置直接運行mysqlsh命令,即可得到如下結果:

圖片

此時,完成了mysql shell部署。

二、進行數據庫備份

1、登錄數據庫

使用mysqlsh登錄數據庫,并列出庫名,例如:

[root@VM-4-14-centos ~]# mysqlsh -u root  -p -S /data/mysql/mysql3306/tmp/mysql.sock
Please provide the password for 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock': *********
Save password for 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock'? [Y]es/[N]o/Ne[v]er (default No): 
MySQL Shell 8.0.35
Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock'
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 10
Server version: 8.0.33-25 Percona Server (GPL), Release 25, Revision 60c9e2c5
No default schema selected; type \use <schema> to set one.
 MySQL  localhost  JS > \sql
Switching to SQL mode... Commands end with ;
Fetching global names for auto-completion... Press ^C to stop.
 MySQL  localhost  SQL > show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
| testdb1            |
+--------------------+
6 rows in set (0.0008 sec)
 MySQL  localhost  SQL >

其中登錄語法為:

mysqlsh -u root  -p -S /data/mysql/mysql3306/tmp/mysql.sock

輸入密碼后即可登錄成功,輸入密碼后會確認是否保存密碼,建議選擇No(默認值)。

登錄成功后,可以選擇\sql ,即SQL命令模式。

圖片

2、備份整個實例

 創建備份目錄。

mkdir -p /data/backup

登錄數據庫。

mysqlsh -u root  -p -S /data/mysql/mysql3306/tmp/mysql.sock

登錄后是在js模式下,備份數據是在JS模式下進行,因此不用切換。

備份整個實例

MySQL  localhost  JS > util.dumpInstance("/data/backup")
Acquiring global read lock
Global read lock acquired
Initializing - done 
2 out of 6 schemas will be dumped and within them 12 tables, 0 views.
2 out of 5 users will be dumped.
Gathering information - done 
All transactions have been started
Locking instance for backup
Global read lock has been released
Writing global DDL files
Writing users DDL
Running data dump using 4 threads.
NOTE: Progress information uses estimated values and may not be accurate.
Writing schema metadata - done       
Writing DDL - done         
Writing table metadata - done         
Starting data dump
129% (870 rows / ~670 rows), 0.00 rows/s, 0.00 B/s uncompressed, 0.00 B/s compressed
Dump duration: 00:00:00s                                                            
Total duration: 00:00:00s                                                           
Schemas dumped: 2                                                                   
Tables dumped: 12                                                                   
Uncompressed data size: 14.06 MB                                                    
Compressed data size: 4.88 MB                                                       
Compression ratio: 2.9                                                              
Rows written: 870                                                                   
Bytes written: 4.88 MB                                                              
Average uncompressed throughput: 14.06 MB/s                                         
Average compressed throughput: 4.88 MB/s                                            
MySQL  localhost  JS >

如無異常,即完成了實例備份。可見,備份效率比較高(4線程處理)。

備份后,備份目錄結果里可以查看結果如下:

圖片

其中的主要文件解釋:

@.done.json: 該文件記錄了備份結束時間,每個庫下每個表的大小等信息,例如:

圖片

@.json:該文件記錄了客戶端版本,備份類型(實例、庫或表等),元數據信息以及binlog信息(點位及GTID)。例如:

圖片

@.sql, @.post.sql:這兩個文件記錄注釋信息. 導入數據時, 我們可以通過這兩個文件自定義的SQL. 在數據導入前和數據導入后執行,本次為全量備份,因此只有版本等注釋信息。

庫名.json: 記錄的是對應庫名、表等信息。

圖片

庫名.sql: 具體的建庫SQL腳本。

圖片

庫名@表名.json:記錄了對于的表的元數據信息,包括庫名,表名,字段名,主鍵等信息。

圖片

庫名@表名.sql: 具體的建表SQL腳本。

圖片

庫名@表名@@*.tsv.zst: 具體數據文件。

圖片

庫名@表名@@*.tsv.zst.idx: 具體索引文件。

圖片

@.users.sql : 數據庫用戶信息,包含創建用戶以及授權的SQL腳本。

3、備份指定庫

創建備份目錄:重新創建一個專用于備份指定庫的目錄。

mkdir -p data/backup/backup_schemas

圖片

使用shellsh登錄數據庫,并查看當前有哪些庫。

# mysqlsh -u root  -p -S /data/mysql/mysql3306/tmp/mysql.sock
Please provide the password for 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock': *********
Save password for 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock'? [Y]es/[N]o/Ne[v]er (default No): 
MySQL Shell 8.0.35
Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock'
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 28
Server version: 8.0.33-25 Percona Server (GPL), Release 25, Revision 60c9e2c5
No default schema selected; type \use <schema> to set one.
 MySQL  localhost  JS > \sql
Switching to SQL mode... Commands end with ;
Fetching global names for auto-completion... Press ^C to stop.
 MySQL  localhost  SQL > show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
| testdb1            |
+--------------------+
6 rows in set (0.0010 sec)

備份指定的庫(schema),如果多個庫,則用逗號分隔。

MySQL  localhost  SQL > \js
Switching to JavaScript mode...
 MySQL  localhost  JS > util.dumpSchemas(['testdb'],'/data/backup/backup_schemas')
Acquiring global read lock
Global read lock acquired
Initializing - done 
1 schemas will be dumped and within them 11 tables, 0 views.
Gathering information - done 
All transactions have been started
Locking instance for backup
Global read lock has been released
Writing global DDL files
Running data dump using 4 threads.
NOTE: Progress information uses estimated values and may not be accurate.
Writing schema metadata - done       
Writing DDL - done         
Writing table metadata - done         
Starting data dump
130% (862 rows / ~662 rows), 0.00 rows/s, 0.00 B/s uncompressed, 0.00 B/s compressed
Dump duration: 00:00:00s                                                            
Total duration: 00:00:00s                                                           
Schemas dumped: 1                                                                   
Tables dumped: 11                                                                   
Uncompressed data size: 14.06 MB                                                    
Compressed data size: 4.88 MB                                                       
Compression ratio: 2.9                                                              
Rows written: 862                                                                   
Bytes written: 4.88 MB                                                              
Average uncompressed throughput: 14.06 MB/s                                         
Average compressed throughput: 4.88 MB/s                                            
 MySQL  localhost  JS >

以上則備份完成。

到對于目錄下查看備份結果如下:

圖片

4、備份指定表

再次先創建目錄。

[root@VM-4-14-centos ~]# mkdir -p /data/backup/backup_tables
[root@VM-4-14-centos ~]# cd /data/backup/backup_tables
[root@VM-4-14-centos backup_tables]#

登錄數據庫,并查看庫及表名。

[root@VM-4-14-centos backup_tables]# mysqlsh -u root  -p -S /data/mysql/mysql3306/tmp/mysql.sock
Please provide the password for 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock': *********
Save password for 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock'? [Y]es/[N]o/Ne[v]er (default No): 
MySQL Shell 8.0.35
Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock'
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 35
Server version: 8.0.33-25 Percona Server (GPL), Release 25, Revision 60c9e2c5
No default schema selected; type \use <schema> to set one.
 MySQL  localhost  JS > \sql
Switching to SQL mode... Commands end with ;
Fetching global names for auto-completion... Press ^C to stop.
 MySQL  localhost  SQL > show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
| testdb1            |
+--------------------+
6 rows in set (0.0009 sec)
 MySQL  localhost  SQL > use testdb1
Default schema set to `testdb1`.
Fetching global names, object names from `testdb1` for auto-completion... Press ^C to stop.
 MySQL  localhost  testdb1  SQL > show tables;
+-------------------+
| Tables_in_testdb1 |
+-------------------+
| test1             |
+-------------------+
1 row in set (0.0014 sec)
 MySQL  localhost  testdb1  SQL >

進行指定表的備份,如果多個表,則表名用逗號分隔。

MySQL  localhost  testdb1  JS >  util.dumpTables('testdb1',['test1'],'/data/backup/backup_tables')
Acquiring global read lock
Global read lock acquired
Initializing - done 
1 tables and 0 views will be dumped.
Gathering information - done 
All transactions have been started
Locking instance for backup
Global read lock has been released
Writing global DDL files
Running data dump using 4 threads.
NOTE: Progress information uses estimated values and may not be accurate.
Writing schema metadata - done       
Writing DDL - done       
Writing table metadata - done       
Starting data dump
100% (8 rows / ~8 rows), 0.00 rows/s, 0.00 B/s uncompressed, 0.00 B/s compressed
Dump duration: 00:00:00s                                                        
Total duration: 00:00:00s                                                       
Schemas dumped: 1                                                               
Tables dumped: 1                                                                
Uncompressed data size: 157 bytes                                               
Compressed data size: 90 bytes                                                  
Compression ratio: 1.7                                                          
Rows written: 8                                                                 
Bytes written: 90 bytes                                                         
Average uncompressed throughput: 157.00 B/s                                     
Average compressed throughput: 90.00 B/s                                        
 MySQL  localhost  testdb1  JS >

查看備份結果:

圖片

至此,備份數據庫實例、庫、表的命令已簡單演示完畢,實際生產使用過程基本會用腳本實現,大家可以自行編寫。

責任編輯:姜華 來源: 數據庫干貨鋪
相關推薦

2023-12-01 15:50:46

2010-05-27 14:55:40

簡單備份MySQL

2011-03-30 13:57:41

MySQL數據庫自動備份

2011-03-31 14:34:46

cactimysql備份

2019-03-01 13:40:01

MySQL數據庫備份案例

2015-03-18 13:39:35

MySQLBackup數據庫備份種類

2010-06-04 09:58:03

MySQL數據庫備份

2011-03-04 14:39:03

MySQL數據庫mysqldump

2019-12-13 10:31:45

數據庫SQLMySQL

2010-06-09 11:32:51

MySQL數據庫備份

2011-05-16 09:32:33

mysql數據庫備份

2018-08-24 13:58:13

數據庫MySQL備份

2010-10-22 11:31:53

SQL Server自

2010-05-31 18:16:48

MySQL數據庫備份

2011-08-15 09:48:30

MySQL數據庫完整備份增量備份

2018-06-07 09:22:16

LinuxMysql備份

2021-09-22 09:55:20

LinuxMySQL數據庫

2013-05-24 13:24:46

Mysql數據庫自動備份

2010-05-31 09:44:38

2010-05-24 16:58:00

MySQL數據庫備份
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲欧美日韩国产 | 日韩精品一区二区三区 | 日本久久福利 | 国产成人精品久久二区二区 | 免费黄色成人 | 久久综合一区 | 三级视频国产 | jvid精品资源在线观看 | 成年人黄色一级毛片 | 亚洲精品一区国产精品 | 99精品久久久久 | 性在线| 久久人人爽人人爽人人片av免费 | 99精品国产一区二区青青牛奶 | 男女视频网站 | 五月天综合影院 | 免费黄色片在线观看 | 日韩中文字幕2019 | 亚洲另类视频 | 中国一级毛片免费 | 久久国产婷婷国产香蕉 | 久久国产视频网站 | 人人射人人 | 国产在线aa | 久草网址 | 韩日视频在线观看 | 亚洲一区二区三区高清 | 日韩一二区| 日屁网站| 正在播放一区二区 | 国产午夜精品福利 | 亚洲视频在线观看一区二区三区 | 日韩午夜精品 | 成人在线视频观看 | 午夜资源| 久久免费视频在线 | 色在线视频网站 | 国产精品国产亚洲精品看不卡15 | 国产一区二区成人 | 99热这里都是精品 | 欧美日韩精品久久久免费观看 |