最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL Shell的介紹以及安裝

 更新時(shí)間:2021年04月23日 11:50:18   作者:DBA隨筆  
這篇文章主要介紹了MySQL Shell的介紹以及安裝,幫助大家更好的理解和學(xué)習(xí)使用MySQL數(shù)據(jù)庫(kù),感興趣的朋友可以了解下

01 ReplicaSet的架構(gòu)

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

通過上面的圖,不難看出,MySQL Shell是運(yùn)維人員管理底層MySQL節(jié)點(diǎn)的入口,也就是DBA執(zhí)行管理命令的地方,而MySQL Router是應(yīng)用程序連接的入口,它的存在,讓底層的架構(gòu)對(duì)應(yīng)用程序透明,應(yīng)用程序只需要連接MySQL Router就可以和底層的數(shù)據(jù)庫(kù)打交道,而數(shù)據(jù)庫(kù)的主從架構(gòu),都是記錄在MySQL Router的原信息里面的。

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

02 MySQL Shell的介紹以及安裝

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

    它的安裝過程比較簡(jiǎn)單:在MySQL官網(wǎng)下載對(duì)應(yīng)版本的MySQL Shell即可。地址如下:

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

這里使用8.0.20版本

下載完畢之后,在Linux服務(wù)器進(jìn)行解壓,然后就可以通過這個(gè)MySQL Shell來連接線上的MySQL服務(wù)了。

我的線上MySQL地址分別是:

192.168.1.10  5607

192.168.1.20  5607

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

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

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

MySQL Shell 8.0.20

Copyright (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 831
Server version: 8.0.19 MySQL Community Server - GPL
No 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連接數(shù)據(jù)庫(kù)并創(chuàng)建ReplicaSet

   上面已經(jīng)介紹了使用MySQL Shell連接數(shù)據(jù)庫(kù)的方法了,現(xiàn)在我們來看利用MySQL Shell來創(chuàng)建ReplicaSet的方法:

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

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:5607
WARNING: 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)

可以看到,上面的命令中,我們配置了副本集的一個(gè)實(shí)例:192.168.1.10:5607,并創(chuàng)建了一個(gè)管理員賬號(hào)rsadmin,同時(shí)這個(gè)管理員擁有clusterAdmin的權(quán)限。

返回的結(jié)果中,有一個(gè)報(bào)錯(cuò)信息,它提示我們登陸的root賬號(hào)少了replication_applier的權(quán)限,因此無法使用root賬號(hào)對(duì)rsadmin賬號(hào)授權(quán)。我們給root賬號(hào)補(bǔ)充replication_applier權(quán)限之后,重新執(zhí)行上面的命令,結(jié)果如下:

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:5607
User '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.

這次執(zhí)行成功了。

我們登陸到底層的192.168.1.10上,查看rsadmin賬號(hào),可以發(fā)現(xiàn),賬號(hào)已經(jīng)生成了,信息如下:

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)

注意,如果我們加入的副本集實(shí)例是當(dāng)前連接的實(shí)例,那么也可以使用簡(jiǎn)單的寫法:

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

2、使用dba.createReplicaSet命令創(chuàng)建副本集,并將結(jié)果保存在一個(gè)變量里面,如下:

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:5607

This instance reports its own address as 192.168.1.10:5607
192.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.

可以看到,我們創(chuàng)建了一個(gè)yeyz_test的副本集,并將結(jié)果保存在變量rs當(dāng)中。

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

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"
    }
}

這里面,可以看到,當(dāng)前ReplicaSet里面已經(jīng)有192.168.1.10:5607這個(gè)實(shí)例的,他的狀態(tài)是available,他的角色是Primary。

4、此時(shí)我們使用rs.addInstance命令加入第2個(gè)節(jié)點(diǎn),并使用rs.status查看狀態(tài)。

這里需要注意,加入第二個(gè)節(jié)點(diǎn)的時(shí)候,有一個(gè)數(shù)據(jù)同步的過程,這個(gè)數(shù)據(jù)同步有2中策略:

策略一:全量恢復(fù)

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

策略二:增量恢復(fù)

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

當(dāng)一個(gè)實(shí)例加入一個(gè)集群的時(shí)候,MySQL Shell會(huì)自動(dòng)嘗試挑選一個(gè)合適的策略來同步數(shù)據(jù),不需要人為干預(yù),如果它無法安全的選擇同步方法,則會(huì)提供給DBA一個(gè)選項(xiàng),讓你選擇是通過Clone或者增量同步的方法來實(shí)現(xiàn)數(shù)據(jù)同步。

下面的例子中,就是通過自動(dòng)選擇增量同步的方法來同步數(shù)據(jù)的:

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 checks

This instance reports its own address as 192.168.1.20:5607
192.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"
    }
}

加入第二個(gè)節(jié)點(diǎn)之后,可以看到,再次使用rs.status來查看副本集的結(jié)構(gòu),可以看到Secondary節(jié)點(diǎn)已經(jīng)出現(xiàn)了,就是我們新加入的192.168.1.20:5607

當(dāng)然我們可以分別使用下面的命令查看更詳細(xì)的輸出:

rs.status({extended:0})

rs.status({extended:1})

rs.status({extended:2})

不同的級(jí)別,顯示的信息有所不同,等級(jí)越高,信息約詳細(xì)。

這里不得不說一個(gè)小的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().

但是實(shí)際操作過程中,這種寫法會(huì)報(bào)錯(cuò),如下:

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)

不知道算不算一個(gè)bug。

5.搭建好副本集之后,查看primary節(jié)點(diǎn)的元信息庫(kù)表,并在primary寫入數(shù)據(jù),查看數(shù)據(jù)是否可以同步。

[(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_metadata
Database 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節(jié)點(diǎn)上有一個(gè)元信息數(shù)據(jù)庫(kù)mysql_innodb_cluster_metadata,里面保存了一些原信息,我們查看了router表,發(fā)現(xiàn)里面沒有數(shù)據(jù),原因是我們沒有配置MySQL Router。后面的文章中會(huì)寫到MySQL Router的配置過程。

    在Primary上創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)yeyazhou,可以發(fā)現(xiàn),在從庫(kù)上也已經(jīng)出現(xiàn)了對(duì)應(yīng)的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)

說明副本集的復(fù)制關(guān)系無誤。

至此,整個(gè)MySQL Shell連接MySQL實(shí)例并創(chuàng)建ReplicatSet的過程搭建完畢。

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

以上就是MySQL Shell的介紹以及安裝的詳細(xì)內(nèi)容,更多關(guān)于MySQL Shell的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • mysql5.7創(chuàng)建用戶授權(quán)刪除用戶撤銷授權(quán)

    mysql5.7創(chuàng)建用戶授權(quán)刪除用戶撤銷授權(quán)

    這篇文章主要介紹了mysql5.7創(chuàng)建用戶授權(quán)刪除用戶撤銷授權(quán)的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-02-02
  • MySQL中的批量修改、插入操作數(shù)據(jù)庫(kù)

    MySQL中的批量修改、插入操作數(shù)據(jù)庫(kù)

    在平常的項(xiàng)目中,我們會(huì)需要批量操作數(shù)據(jù)庫(kù)的時(shí)候,例如:批量修改,批量插入,那我們不應(yīng)該使用 for 循環(huán)去操作數(shù)據(jù)庫(kù),這樣會(huì)導(dǎo)致我們反復(fù)與數(shù)據(jù)庫(kù)發(fā)生連接和斷開連接,影響性能和增加操作時(shí)間,所以可以使用SQL 批量修改的方式去操作數(shù)據(jù)庫(kù),感興趣的朋友一起學(xué)習(xí)下吧
    2023-09-09
  • 阿里云 Centos7.3安裝mysql5.7.18 rpm安裝教程

    阿里云 Centos7.3安裝mysql5.7.18 rpm安裝教程

    這篇文章主要介紹了阿里云 Centos7.3安裝mysql5.7.18 rpm安裝教程,需要的朋友可以參考下
    2017-06-06
  • MySQL利用UNION連接2個(gè)查詢排序失效詳解

    MySQL利用UNION連接2個(gè)查詢排序失效詳解

    這篇文章主要給大家介紹了關(guān)于MySQL利用UNION連接2個(gè)查詢排序失效的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用MySQL具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Mysql?刪除重復(fù)數(shù)據(jù)保留一條有效數(shù)據(jù)(最新推薦)

    Mysql?刪除重復(fù)數(shù)據(jù)保留一條有效數(shù)據(jù)(最新推薦)

    這篇文章主要介紹了Mysql?刪除重復(fù)數(shù)據(jù)保留一條有效數(shù)據(jù),實(shí)現(xiàn)原理也很簡(jiǎn)單,mysql刪除重復(fù)數(shù)據(jù),多個(gè)字段分組操作,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • mysql 5.7.16 安裝配置方法圖文教程

    mysql 5.7.16 安裝配置方法圖文教程

    這篇文章主要為大家分享了mysql 5.7.16winx64安裝配置方法圖文教程,感興趣的朋友可以參考一下
    2016-10-10
  • MySQL數(shù)據(jù)庫(kù)之內(nèi)置函數(shù)和自定義函數(shù) function

    MySQL數(shù)據(jù)庫(kù)之內(nèi)置函數(shù)和自定義函數(shù) function

    這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)之內(nèi)置函數(shù)和自定義函數(shù) function,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下
    2022-06-06
  • 關(guān)于MySQL中Update使用方法舉例

    關(guān)于MySQL中Update使用方法舉例

    這篇文章主要給大家介紹了關(guān)于MySQL中Update使用方法的相關(guān)資料,更新數(shù)據(jù)是使用數(shù)據(jù)庫(kù)時(shí)最重要的任務(wù)之一,在本教程中您將學(xué)習(xí)如何使用MySQL UPDATE語句來更新表中的數(shù)據(jù),需要的朋友可以參考下
    2023-11-11
  • MySQL深入淺出精講觸發(fā)器用法

    MySQL深入淺出精講觸發(fā)器用法

    觸發(fā)器是SQLserver提供給程序員和數(shù)據(jù)分析員來保證數(shù)據(jù)完整性的一種方法,它是與表事件相關(guān)的特殊的存儲(chǔ)過程,事件是在 MySQL 5.1后引入的,有點(diǎn)類似操作系統(tǒng)的計(jì)劃任務(wù),但是周期性任務(wù)是內(nèi)置在MySQL服務(wù)端執(zhí)行的
    2022-08-08
  • MySQL數(shù)據(jù)xtrabackup物理備份的方式

    MySQL數(shù)據(jù)xtrabackup物理備份的方式

    Xtrabackup是開源免費(fèi)的支持MySQL 數(shù)據(jù)庫(kù)熱備份的軟件,在 Xtrabackup 包中主要有 Xtrabackup 和 innobackupex 兩個(gè)工具,本文給大家介紹MySQL數(shù)據(jù)xtrabackup物理備份方法,感興趣的朋友跟隨小編一起看看吧
    2023-10-10

最新評(píng)論

华坪县| 门头沟区| 红桥区| 阿瓦提县| 新乐市| 启东市| 遵义县| 临洮县| 莱西市| 玉溪市| 宾阳县| 六安市| 华安县| 闽侯县| 青冈县| 绥棱县| 峨山| 永川市| 类乌齐县| 泾阳县| 苍梧县| 梧州市| 阿瓦提县| 丹巴县| 宣城市| 卓尼县| 八宿县| 重庆市| 上犹县| 府谷县| 宁德市| 香港| 兴隆县| 吴忠市| 普兰店市| 水城县| 五峰| 越西县| 噶尔县| 潞城市| 兴安县|