[root@master ~]# systemctl enable --now mysqld [root@master ~]# cat /var/log/mysqld.log | grep password # 初次安装自动生成密码,通过日志查看 2022-10-12T16:51:22.192080Z 1 [Note] A temporary password is generated for root@localhost: dF4q%Xs6ylyP [root@master ~]# mysql -uroot -pdF4q%Xs6ylyP mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.39-log
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql># 初次登陆需要重置密码 mysql> set global validate_password_policy=0; # 设置密码策略 如果对安全有要求可以跳过这两项操作,这里主要是为了演示采用简单密码 mysql> set global validate_password_length=1; # 设置密码长度 mysql> alter user 'root'@'localhost' identified by '123456'; # 更新root密码 mysql> show master status; # 查看master状态,可以看到二进制日志文件的名称 +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000002 | 398 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> grant replication slave,replication client on *.* to slave@"192.168.64.*" identified by '123456'; # 创建复制账号并设置密码
安装从节点
1 2 3 4
[root@slave ~]# ls anaconda-ks.cfg mysql-5.7.39-1.el7.x86_64.rpm-bundle.tar [root@slave ~]# tar xf mysql-5.7.39-1.el7.x86_64.rpm-bundle.tar [root@slave ~]# dnf -y install *.rpm
[root@slave ~]# systemctl enable --now mysqld [root@slave ~]# cat /var/log/mysqld.log | grep password 2022-10-12T17:11:25.637271Z 1 [Note] A temporary password is generated for root@localhost: mHJ5aTJE+grU [root@slave ~]# mysql -uroot -pmHJ5aTJE+grU mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.39-log
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set global validate_password_policy=0; # 更改密码复杂度 Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_length=1; # 更改密码策略长度 Query OK, 0 rows affected (0.00 sec) mysql> alter user 'root'@'localhost' identified by '123456'; # 更改root密码 Query OK, 0 rows affected (0.00 sec) mysql> change master to master_host="192.168.64.147", # 配置复制账号信息 -> master_user="slave", -> master_password="123456", -> master_log_file="mysql-bin.000002", -> master_log_pos=0; Query OK, 0 rows affected, 2 warnings (0.00 sec) mysql> show slave status\G # 查看slave状态 *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.64.147 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 4 Relay_Log_File: slave-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 4 Relay_Log_Space: 154 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 0 Master_UUID: Master_Info_File: /var/lib/mysql/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) mysql> start slave; # 启动复制,关闭使用stop slave; Query OK, 0 rows affected (0.00 sec) mysql> show slave status\G # 查看状态 *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.64.147 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 1028 Relay_Log_File: slave-relay-bin.000002 Relay_Log_Pos: 1241 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes # IO启动 确保这两项为Yes Slave_SQL_Running: Yes # SQL启动 Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 1028 Relay_Log_Space: 1448 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 10 Master_UUID: 19e30d90-4a4e-11ed-9534-000c2952ba66 Master_Info_File: /var/lib/mysql/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)