激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|數據庫技術|

服務器之家 - 數據庫 - Mysql - 轉戰MySQL Shell!數據庫備份新姿勢,輕松搞定備份操作!

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

2023-12-14 01:00未知服務器之家 Mysql

一、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 SM

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

一、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.

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

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

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

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!數據庫備份新姿勢,輕松搞定備份操作!

此時,完成了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命令模式。

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

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線程處理)。

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

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

其中的主要文件解釋:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3、備份指定庫

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

mkdir -p data/backup/backup_schemas

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

使用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 >

以上則備份完成。

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

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

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 >

查看備份結果:

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产色视频在线观看免费 | 玖玖视频精品 | 深夜精品福利 | 国产精品片一区二区三区 | 亚洲欧美日韩综合一区 | 91社影院在线观看 | 在线看免电影网站 | 欧美伦理一区二区 | 91精品国产免费久久 | 日韩剧情片 | 91精品久久久久久久久 | 国产精品jk白丝蜜臀av软件 | 国产高清片 | 在线成人av观看 | 黄网站免费在线看 | 毛片视频播放 | 久久草在线视频国产 | 小雪奶水翁胀公吸小说最新章节 | www.精品一区| 97伦理 | 成人免费网站在线观看视频 | 毛片视频网址 | 爱操影视 | 黄色免费不卡视频 | 最近中文字幕一区二区 | 性欧美日本 | 色的综合 | 色悠悠久久久久 | 蜜桃网在线观看 | chinese 军人 gay xx 呻吟 | 色屁屁xxxxⅹ在线视频 | 毛片视频播放 | 国产精品午夜未成人免费观看 | 久久国产精品久久久久久电车 | 国产成人羞羞视频在线 | 国产a级久久 | 亚洲一区在线视频 | 亚洲黑人在线观看 | 国产精品视频成人 | 久久久久免费精品 | 久草在线最新 |