准备mysql 配置文件my.cnf vim /etc/my.cnf default-authentication-plugin=mysql_native_password lower_case_table_names=1 datadir=/data_test socket=/data_test/mysql.sock log-error=/data_test/mysqld.log pid-file=/data_test/mysqld.pid
创建数据目录文件/data_test(用户和用户组均为mysql_tar) 初始化mysql cd /home/mysql_tar/mysql_install/bin(环境变量设置正确,该步可有可无) ./mysqld --initialize --user=mysql_tar(初始化mysql系统表空间和其他重要文件,initialize 拼错的话不会报错,只会提示数据目录找不到) 启动Mysql mysqld_safe --user=mysql_tar & 连接Mysql并且修改root账户密码: ./mysql -u root -S /data_test/mysql.sock -p(也可以通过TCP/IP登陆,这里通过套接字登陆) mysql>alter user root@localhost identified by 'mjj'; 通过mysqlsh登陆mysql、检查环境并创建集群 /home/mysql_tar/mysql_shell/bin/mysqlsh MySQL SQL > /connect root@mysql_host_a(加粗的是我的命令) Creating a session to 'root@mysql_host_a' Please provide the password for 'root@mysql_host_a': * Save password for 'root@mysql_host_a'? [Y]es/[N]o/Ne[v]er (default No): ~~ MySQL mysql_host_a:33060+ ssl JS > dba.checkInstanceConfiguration(); Validating local MySQL instance listening at port 3306 for use in an InnoDB cluster...** This instance reports its own address as mysql_host_a:3306 Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.
Checking whether existing tables comply with Group Replication requirements... No incompatible tables detected
加入节点: MySQL mysql_host_a:33060+ ssl JS > cluster.addInstance('root@mysql_host_b:3306');(本人另一台机子的主机名是mysql_host_b) Cluster.addInstance: Connection 'root@mysql_host_b:3306' is not valid: unable to resolve the IPv4 address. (ArgumentError) MySQL mysql_host_a:33060+ ssl JS > cluster.addInstance('root@mysql_host_b:3306'); Please provide the password for 'root@mysql_host_b:3306': *** Save password for 'root@mysql_host_b:3306'? [Y]es/[N]o/Ne[v]er (default No): NOTE: The target instance 'mysql_host_b:3306' has not been pre-provisioned (GTID set is empty). The Shell is unable to decide whether incremental distributed state recovery can correctly provision it. The safest and most convenient way to provision a new instance is through automatic clone provisioning, which will completely overwrite the state of 'mysql_host_b:3306' with a physical snapshot from an existing cluster member. To use this method by default, set the 'recoveryMethod' option to 'clone'.
Waiting for clone to finish... NOTE: mysql_host_b:3306 is being cloned from mysql_host_a:3306 Stage DROP DATA: Completed Clone Transfer FILE COPY ############################################################ 100% Completed PAGE COPY ############################################################ 100% Completed REDO COPY ############################################################ 100% Completed NOTE: mysql_host_b:3306 is shutting down...
Waiting for server restart... ready mysql_host_b:3306 has restarted, waiting for clone to finish... ** Stage RESTART: Completed Clone process has finished: 58.50 MB transferred in about 1 second (~inf TB/s) State recovery already finished for 'mysql_host_b:3306'
The instance 'mysql_host_b:3306' was successfully added to the cluster.