# #参数解释 # 参数 --bootstrap 表示开始初始化 # 参数 GreatSQL@172.16.16.10:3306 是MGR服务专用账号 # --user=mysqlrouter 是运行mysqlrouter进程的系统用户名 # $ mysqlrouter --bootstrap GreatSQL@172.16.16.10:3306 --user=mysqlrouter Please enter MySQL password for GreatSQL: <-- 输入密码 # 然后mysqlrouter开始自动进行初始化 # 它会自动读取MGR的元数据信息,自动生成配置文件 Please enter MySQL password for GreatSQL: # Bootstrapping system MySQL Router instance...
- Creating account(s) (only those that are needed, if any) - Using existing certificates from the '/var/lib/mysqlrouter' directory - 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 /etc/mysqlrouter/mysqlrouter.conf # MySQL Router configured for the InnoDB Cluster 'MGR1'
After this MySQL Router has been started with the generated configuration
$ /etc/init.d/mysqlrouter restart or $ systemctl start mysqlrouter or $ mysqlrouter -c /etc/mysqlrouter/mysqlrouter.conf
the cluster 'MGR1' can be reached by connecting to: ## MySQL Classic protocol <-- MySQL协议的两个端口
- Read/Write Connections: localhost:6446 - Read/Only Connections: localhost:6447 ## MySQL X protocol <-- MySQL X协议的两个端口
$ mysqlsh --uri GreatSQL@172.16.16.10:3306 ... MySQL 172.16.16.10:3306 ssl JS > var c=dba.getCluster(); MySQL 172.16.16.10:3306 ssl JS > c.setPrimaryInstance('172.16.16.11:3306'); <-- 切换PRIMARY节点 Setting instance '172.16.16.11:3306' as the primary instance of cluster 'MGR1'...
Instance '172.16.16.10:3306' was switched from PRIMARY to SECONDARY. <-- 切换了,从PRIMARY到SECONDARY Instance '172.16.16.11:3306' was switched from SECONDARY to PRIMARY. <-- 切换了,从SECONDARY到PRIMARY Instance '172.16.16.12:3306' remains SECONDARY. <-- 保持不变
WARNING: The cluster internal session is not the primary member anymore. For cluster management operations please obtain a fresh cluster handle using dba.getCluster().
The instance '172.16.16.11:3306' was successfully elected as primary.
回到前面连接6446端口的那个会话,再次查询 server_uuid,此时会发现连接自动断开了:
1 2 3 4 5 6 7 8 9 10 11 12 13
mysql> select @@server_uuid; ERROR 2013 (HY000): Lost connection to MySQL server during query mysql> select @@server_uuid; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 157990 Current database: *** NONE ***