
手动创建集群
如果在已经配置好的组复制上创建 InnoDB Cluster,需要使用 MySQL Shell 来创建集群,
将 adoptFromGR 选项传递给 dba.createCluster()函数。创建的 InnoDB Cluster 会匹配复制组
是以单主数据库还是多主数据库运行。
初始化实例及创建元数据库,库名 mysql_innodb_cluster_metadata。
1.安装 MySQL Shell(mgr01、mgr02、mgr03)
wget https://downloads.mysql.com/archives/get/p/43/file/mysql-shell-8.0.33-
1.el7.x86_64.rpm
yum -y install mysql-shell-8.0.33-1.el7.x86_64.rpm
2.连接数据库,添加元数据库
在第一次连接,创建元数据库时,需要从 primary 连接进去。否则会破坏 read_only(root
用户会破坏 super_read_only)。
mysqlsh root:123456@mgr01:3306
添加元数据库
dba.create_cluster('cluster')
MySQL mgr01:3306 ssl JS > dba.createCluster('cluster')
A new InnoDB Cluster will be created on instance 'mgr02:3306'.
You are connected to an instance that belongs to an unmanaged replication group.
Do you want to setup an InnoDB Cluster based on this replication group? [Y/n]: Y
Creating InnoDB Cluster 'cluster' on 'mgr01:3306'...
Adding Seed Instance...
Adding Instance 'mgr01:3306'...
Adding Instance 'mgr02:3306'...
Adding Instance 'mgr03:3306'...
Resetting distributed recovery credentials across the cluster...
NOTE: User 'mysql_innodb_cluster_1'@'%' already existed at instance 'mgr01:3306'. It
will be deleted and created again with a new password.
NOTE: User 'mysql_innodb_cluster_2'@'%' already existed at instance 'mgr01:3306'. It
will be deleted and created again with a new password.
NOTE: User 'mysql_innodb_cluster_3'@'%' already existed at instance 'mgr01:3306'. It
will be deleted and created again with a new password.
Cluster successfully created based on existing replication group.
如果报以下错误,则添加相应权限
mysqlsh.DBError: MySQL Error (3630): Dba.create_cluster: Access denied; you need
SYSTEM_VARIABLES_ADMIN and PERSIST_RO_VARIABLES_ADMIN privileges
for this operation
--在主库上添加权限
grant SYSTEM_VARIABLES_ADMIN,PERSIST_RO_VARIABLES_ADMIN on *.* to
root;
评论