色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

MySQL Shell的介紹以及安裝

瀏覽:3日期:2023-10-03 16:24:07
01 ReplicaSet的架構

前面的文章中,我們說了ReplicaSet的基本概念和限制以及部署前的基本知識。今天我們來看InnoDB ReplicaSet部署過程中的兩個重要組件之一的MySQL Shell,為了更好的理解MySQL Shell,畫了一張圖,如下:

MySQL Shell的介紹以及安裝

通過上面的圖,不難看出,MySQL Shell是運維人員管理底層MySQL節點的入口,也就是DBA執行管理命令的地方,而MySQL Router是應用程序連接的入口,它的存在,讓底層的架構對應用程序透明,應用程序只需要連接MySQL Router就可以和底層的數據庫打交道,而數據庫的主從架構,都是記錄在MySQL Router的原信息里面的。

今天,我們主要來看MySQL Shell的搭建過程。

02 MySQL Shell的介紹以及安裝

MySQL Shel是一個客戶端工具,用于管理Innodb Cluster或者Innodb ReplicaSet,可以簡單理解成ReplicaSet的一個入口。

它的安裝過程比較簡單:在MySQL官網下載對應版本的MySQL Shell即可。地址如下:

https://downloads.mysql.com/archives/shell/

這里使用8.0.20版本

MySQL Shell的介紹以及安裝

下載完畢之后,在Linux服務器進行解壓,然后就可以通過這個MySQL Shell來連接線上的MySQL服務了。

我的線上MySQL地址分別是:

192.168.1.10 5607

192.168.1.20 5607

可以直接通過下面的命令來連接MySQL服務:

/usr/local/mysql-shell-8.0.20/bin/mysqlsh ’$user’@’$host’:$port --password=$pass

成功連接之后的日志如下:

MySQL Shell 8.0.20Copyright (c) 2016, 2020, 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 ’?’ for help; ’quit’ to exit.WARNING: Using a password on the command line interface can be insecure.Creating a session to ’superdba@10.185.13.195:5607’Fetching schema names for autocompletion... Press ^C to stop.Your MySQL connection id is 831Server version: 8.0.19 MySQL Community Server - GPLNo default schema selected; type use <schema> to set one. MySQL 192.168.1.10:5607 ssl JS > MySQL 192.168.1.10:5607 ssl JS > MySQL 192.168.1.10:5607 ssl JS > MySQL 192.168.1.10:5607 ssl JS > 03 MySQL Shell連接數據庫并創建ReplicaSet

上面已經介紹了使用MySQL Shell連接數據庫的方法了,現在我們來看利用MySQL Shell來創建ReplicaSet的方法:

1、首先使用dba.configureReplicaSetInstance命令來配置副本集,并創建副本集的管理員。

MySQL 192.168.1.10:5607 ssl JS > dba.configureReplicaSetInstance(’root@192.168.1.10:5607’,{clusterAdmin:'’rsadmin’@’%’'})Configuring MySQL instance at 192.168.1.10:5607 for use in an InnoDB ReplicaSet...This instance reports its own address as 192.168.1.10:5607WARNING: User ’rsadmin’@’%’ already exists and will not be created. However, it is missing privileges.The account ’rsadmin’@’%’ is missing privileges required to manage an InnoDB cluster:GRANT REPLICATION_APPLIER ON *.* TO ’rsadmin’@’%’ WITH GRANT OPTION;Dba.configureReplicaSetInstance: The account ’root’@’192.168.1.10’ is missing privileges required to manage an InnoDB cluster. (RuntimeError)

可以看到,上面的命令中,我們配置了副本集的一個實例:192.168.1.10:5607,并創建了一個管理員賬號rsadmin,同時這個管理員擁有clusterAdmin的權限。

返回的結果中,有一個報錯信息,它提示我們登陸的root賬號少了replication_applier的權限,因此無法使用root賬號對rsadmin賬號授權。我們給root賬號補充replication_applier權限之后,重新執行上面的命令,結果如下:

MySQL 192.168.1.10:5607 ssl JS > dba.configureReplicaSetInstance(’root@192.168.1.10:5607’,{clusterAdmin:'’rsadmin’@’%’'})Configuring MySQL instance at 192.168.1.10:5607 for use in an InnoDB ReplicaSet...This instance reports its own address as 192.168.1.10:5607User ’rsadmin’@’%’ already exists and will not be created.The instance ’192.168.1.10:5607’ is valid to be used in an InnoDB ReplicaSet.The instance ’192.168.1.10:5607’ is already ready to be used in an InnoDB ReplicaSet.

這次執行成功了。

我們登陸到底層的192.168.1.10上,查看rsadmin賬號,可以發現,賬號已經生成了,信息如下:

select user,host,concat(user,'@’',host,'’'),authentication_string from mysql.user where user like '%%rsadmin';+---------+------+----------------------------+-------------------------------------------+| user | host | concat(user,'@’',host,'’') | authentication_string |+---------+------+----------------------------+-------------------------------------------+| rsadmin | % | rsadmin@’%’| *2090992BE9B9B27D89906C6CB13A8512DF49E439 |+---------+------+----------------------------+-------------------------------------------+1 row in set (0.00 sec)show grants for rsadmin@’%’;+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Grants for rsadmin@%|+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| GRANT SELECT, RELOAD, SHUTDOWN, PROCESS, FILE, SUPER, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE USER ON *.* TO `rsadmin`@`%` WITH GRANT OPTION || GRANT BACKUP_ADMIN,CLONE_ADMIN,PERSIST_RO_VARIABLES_ADMIN,SYSTEM_VARIABLES_ADMIN ON *.* TO `rsadmin`@`%` WITH GRANT OPTION || GRANT INSERT, UPDATE, DELETE ON `mysql`.* TO `rsadmin`@`%` WITH GRANT OPTION || GRANT INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `mysql_innodb_cluster_metadata`.* TO `rsadmin`@`%` WITH GRANT OPTION || GRANT INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `mysql_innodb_cluster_metadata_bkp`.* TO `rsadmin`@`%` WITH GRANT OPTION || GRANT INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `mysql_innodb_cluster_metadata_previous`.* TO `rsadmin`@`%` WITH GRANT OPTION |+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+6 rows in set (0.00 sec)

注意,如果我們加入的副本集實例是當前連接的實例,那么也可以使用簡單的寫法:

dba.configureReplicaSetInstance(’’,{clusterAdmin:'’rsadmin’@’%’'})

2、使用dba.createReplicaSet命令創建副本集,并將結果保存在一個變量里面,如下:

MySQL 192.168.1.10:5607 ssl JS > var rs = dba.createReplicaSet('yeyz_test')A new replicaset with instance ’192.168.1.10:5607’ will be created.* Checking MySQL instance at 192.168.1.10:5607This instance reports its own address as 192.168.1.10:5607192.168.1.10:5607: Instance configuration is suitable.* Updating metadata...ReplicaSet object successfully created for 192.168.1.10:5607.Use rs.addInstance() to add more asynchronously replicated instances to this replicaset and rs.status() to check its status.

可以看到,我們創建了一個yeyz_test的副本集,并將結果保存在變量rs當中。

3、使用rs.status()查看當前的副本集成員

MySQL 192.168.1.10:5607 ssl JS > rs.status(){ 'replicaSet': {'name': 'yeyz_test','primary': '192.168.1.10:5607','status': 'AVAILABLE','statusText': 'All instances available.','topology': { '192.168.1.10:5607': {'address': '192.168.1.10:5607','instanceRole': 'PRIMARY','mode': 'R/W','status': 'ONLINE' }},'type': 'ASYNC' }}

這里面,可以看到,當前ReplicaSet里面已經有192.168.1.10:5607這個實例的,他的狀態是available,他的角色是Primary。

4、此時我們使用rs.addInstance命令加入第2個節點,并使用rs.status查看狀態。

這里需要注意,加入第二個節點的時候,有一個數據同步的過程,這個數據同步有2中策略:

策略一:全量恢復

使用MySQL Clone組件,然后使用克隆快照來覆蓋新實例上面的所有數據。這種方法非常適合空白實例加入到Innodb 副本集中。

策略二:增量恢復

它依賴MySQL的復制功能,將所有的丟失的事務復制到新實例上,如果新實例上的事務很少,則這個過程會很快。這個方法需要保證集群中至少存在一個實例,它保存了這些缺失事務的binlog,如果缺失的事務的binlog已經清理,則這個方法不能使用。

當一個實例加入一個集群的時候,MySQL Shell會自動嘗試挑選一個合適的策略來同步數據,不需要人為干預,如果它無法安全的選擇同步方法,則會提供給DBA一個選項,讓你選擇是通過Clone或者增量同步的方法來實現數據同步。

下面的例子中,就是通過自動選擇增量同步的方法來同步數據的:

MySQL 192.168.1.10:5607 ssl JS > rs.addInstance('192.168.1.20:5607')WARNING: Concurrent execution of ReplicaSet operations is not supported because the required MySQL lock service UDFs could not be installed on instance ’10.41.28.127:5607’.Make sure the MySQL lock service plugin is available on all instances if you want to be able to execute some operations at the same time. The operation will continue without concurrent execution support.Adding instance to the replicaset...* Performing validation checksThis instance reports its own address as 192.168.1.20:5607192.168.1.20:5607: Instance configuration is suitable.* Checking async replication topology...* Checking transaction state of the instance...The safest and most convenient way to provision a new instance is through automatic clone provisioning, which will completely overwrite the state of ’192.168.1.20:5607’ with a physical snapshot from an existing replicaset member. To use this method by default, set the ’recoveryMethod’ option to ’clone’.WARNING: It should be safe to rely on replication to incrementally recover the state of the new instance if you are sure all updates ever executed in the replicaset were done with GTIDs enabled, there are no purged transactions and the new instance contains the same GTID set as the replicaset or a subset of it. To use this method by default, set the ’recoveryMethod’ option to ’incremental’.Incremental state recovery was selected because it seems to be safely usable.* Updating topology** Configuring 192.168.1.20:5607 to replicate from 192.168.1.10:5607** Waiting for new instance to synchronize with PRIMARY...The instance ’192.168.1.20:5607’ was added to the replicaset and is replicating from 192.168.1.20:5607.MySQL 192.168.1.10:5607 ssl JS >MySQL 192.168.1.10:5607 ssl JS > rs.status(){ 'replicaSet': {'name': 'yeyz_test','primary': '192.168.1.10:5607','status': 'AVAILABLE','statusText': 'All instances available.','topology': { '192.168.1.10:5607': {'address': '192.168.1.10:5607','instanceRole': 'PRIMARY','mode': 'R/W','status': 'ONLINE' }, '192.168.1.20:5607': {'address': '192.168.1.20:5607','instanceRole': 'SECONDARY','mode': 'R/O','replication': { 'applierStatus': 'APPLIED_ALL', 'applierThreadState': 'Slave has read all relay log; waiting for more updates', 'receiverStatus': 'ON', 'receiverThreadState': 'Waiting for master to send event', 'replicationLag': null},'status': 'ONLINE' }},'type': 'ASYNC' }}

加入第二個節點之后,可以看到,再次使用rs.status來查看副本集的結構,可以看到Secondary節點已經出現了,就是我們新加入的192.168.1.20:5607

當然我們可以分別使用下面的命令查看更詳細的輸出:

rs.status({extended:0})

rs.status({extended:1})

rs.status({extended:2})

不同的級別,顯示的信息有所不同,等級越高,信息約詳細。

這里不得不說一個小的bug,官方文檔建議寫法是:

ReplicaSet.status(extended=1)

原文如下:

The output of ReplicaSet.status(extended=1) is very similar to Cluster.status(extended=1), but the main difference is that the replication field is always available because InnoDB ReplicaSet relies on MySQL Replication all of the time, unlike InnoDB Cluster which uses it during incremental recovery. For more information on the fields, see Checking a cluster’s Status with Cluster.status().

但是實際操作過程中,這種寫法會報錯,如下:

MySQL 192.168.1.10:5607 ssl JS > sh.status(extended=1)You are connected to a member of replicaset ’yeyz_test’.ReplicaSet.status: Argument #1 is expected to be a map (ArgumentError)

不知道算不算一個bug。

5.搭建好副本集之后,查看primary節點的元信息庫表,并在primary寫入數據,查看數據是否可以同步。

[(none)] 17:41:10>show databases;+-------------------------------+| Database |+-------------------------------+| information_schema || mysql || mysql_innodb_cluster_metadata || performance_schema || sys || zjmdmm|+-------------------------------+6 rows in set (0.01 sec)[(none)] 17:41:29>use mysql_innodb_cluster_metadataDatabase changed[mysql_innodb_cluster_metadata] 17:45:12>show tables;+-----------------------------------------+| Tables_in_mysql_innodb_cluster_metadata |+-----------------------------------------+| async_cluster_members || async_cluster_views || clusters|| instances || router_rest_accounts || routers || schema_version || v2_ar_clusters || v2_ar_members || v2_clusters || v2_gr_clusters || v2_instances || v2_router_rest_accounts || v2_routers || v2_this_instance|+-----------------------------------------+15 rows in set (0.00 sec)[mysql_innodb_cluster_metadata] 17:45:45>select * from routers;Empty set (0.00 sec)[(none)] 17:45:52>create database yeyazhou;Query OK, 1 row affected (0.00 sec)

可以看到,Primary節點上有一個元信息數據庫mysql_innodb_cluster_metadata,里面保存了一些原信息,我們查看了router表,發現里面沒有數據,原因是我們沒有配置MySQL Router。后面的文章中會寫到MySQL Router的配置過程。

在Primary上創建一個數據庫yeyazhou,可以發現,在從庫上也已經出現了對應的DB,

192.168.1.20 [(none)] 17:41:41>show databases;+-------------------------------+| Database |+-------------------------------+| information_schema || mysql || mysql_innodb_cluster_metadata || performance_schema || sys || yeyazhou || zjmdmm|+-------------------------------+7 rows in set (0.00 sec)

說明副本集的復制關系無誤。

至此,整個MySQL Shell連接MySQL實例并創建ReplicatSet的過程搭建完畢。

下一篇文章講述MySQL Router的搭建過程,以及如何使用MySQL Router來訪問底層的數據庫。

以上就是MySQL Shell的介紹以及安裝的詳細內容,更多關于MySQL Shell的資料請關注好吧啦網其它相關文章!

標簽: MySQL 數據庫
相關文章:
主站蜘蛛池模板: 成人网久久 | 天天舔夜夜操 | 亚洲在线网站 | 欧美aaaaa一级毛片在线 | 日韩精品久久一区二区三区 | 美女黄页网 | 大狠狠大臿蕉香蕉大视频 | 日本尹人综合香蕉在线观看 | 欧美人在线一区二区三区 | 国产亚洲欧美日韩在线观看不卡 | 久草视频在线网 | 天天干亚洲 | 亚欧成人 | 九九久久九九久久 | 九九久久九九久久 | 天堂一区二区三区精品 | 成 人 a v免费视频 | 韩国一级永久免费观看网址 | 国产自在自线午夜精品视频在 | 久草热久 | 日本免费视频观看在线播放 | 日韩中文字幕免费 | 无国产精品白浆是免费 | 九九精品激情在线视频 | 在线日本看片免费人成视久网 | 日本草草视频在线观看 | a毛片全部播放免费视频完整18 | 亚洲精品国产第一区二区多人 | 国产美女视频一区 | 久久亚洲国产高清 | 日韩 欧美 自拍 | 亚洲精品亚洲人成在线麻豆 | 亚洲黄色成人 | 免费观看欧美一区二区三区 | 精品国产欧美一区二区 | 日本一区二区三区不卡在线视频 | 国产欧美日韩在线不卡第一页 | 特级一级毛片视频免费观看 | 亚洲美女视频在线观看 | 明星国产欧美日韩在线观看 | 色综合久久综合 |