MySQL InnoDB 集群为 MySQL 提供了完整的高可用性解决方案。 MySQL Shell包含AdminAPI,能轻松配置和管理MySQL实例组,组内的每个MySQL实例都运行MGR,MGR提供了InnoDB集群内部数据复制和内置的故障转移功能。 MySQL Router 能够根据部署的集群进行自我配置,将连接客户端的应用转移到后端服务器实例上。
InnoDB Cluster 概述
如图所示,3个MySQL server 实例,组成了单主模式的高可用集群;MySQL router 负责将客户端应用的连接请求转发到后端MySQL实例上;MySQL Shell包含AdminAPI,可通过dba全局变量部署,配置和管理InnoDB的集群。
InnoDB Cluster 创建
连接实例
通过MySQL shell 连接任意一个实例: cd /opt/soft/mysqlshell ./mysqlsh –mysql –uri root@localhost:3008 …… Server version: 8.0.18 MySQL Community Server - GPL No default schema selected; type \use to set one. MySQL localhost:3008 ssl JS >
MySQL localhost:3008 ssl JS > dba.createCluster('testcluster') A new InnoDB cluster will be created on instance 'localhost:3008'.
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 'testcluster' on 'bjm6-184-40.com.cn:3008'...
Adding Seed Instance... Adding Instance 'bjm6-184-40.com.cn:3008'... Adding Instance 'bjm6-196-59.com.cn:3009'... Adding Instance 'bjm6-196-85.com.cn:3010'... Resetting distributed recovery credentials across the cluster... Cluster successfully created based on existing replication group.
GRANTSELECT, EXECUTEON mysql_innodb_cluster_metadata.* TO'mysql_router1_3crooltaqbd0'@'%'": Access denied for user 'root'@'192.168.184.40' to database 'mysql_innodb_cluster_metadata'
[root(cuigenlu)@bjm6-184-40 bin]# ./mysqlrouter --bootstrap localhost:3008 --directory /work/myrouter --force --user root Please enter MySQL password for root: # Bootstrapping MySQL Router instance at '/work/myrouter'...
- Creating account(s) (only those that are needed, if any) - Verifying account (using it to run SQL queries that would be run by Router) - Storing account in keyring - Adjusting permissions of generated files - Creating configuration /work/myrouter/mysqlrouter.conf
# MySQL Router configured for the InnoDB Cluster 'testcluster'
After this MySQL Router has been started with the generated configuration
[root(cuigenlu)@bjm6-184-40 bin]# ./mysqlrouter --bootstrap 192.168.184.40:3008 --directory /work/myrouter --user root Please enter MySQL password for root: # Bootstrapping MySQL Router instance at '/work/myrouter'...
- Creating account(s) (only those that are needed, if any) FATAL ERROR ENCOUNTERED, attempting to undo new accounts that were created - New accounts cleaned up successfully Error: Error creating MySQL account for router (GRANTs stage): Error executing MySQL query "GRANT SELECT, EXECUTE ON mysql_innodb_cluster_metadata.* TO 'mysql_router1_3crooltaqbd0'@'%'": Access denied for user 'root'@'192.168.184.40'to database 'mysql_innodb_cluster_metadata' (1044)
解决:报错是因为,启动router时,账号没有对元数据的访问权限,先赋权,再启动router
P02
1 2 3 4 5 6
[root(cuigenlu)@bjm6-184-40 bin]# ./mysqlrouter --bootstrap localhost:3008 --directory /work/myrouter --user root Please enter MySQL password for root: # Bootstrapping MySQL Router instance at '/work/myrouter'...
Error: It appears that a router instance named '' has been previously configured in this host. If that instance no longer exists, use the --force option to overwrite it. 解决: 报错是因为之前重复启动过router,有异常信息 用 --force强制覆盖