[root@mysql-0001 ~]# grep "password" /var/log/mysqld.log | tail -12022-11-10T09:40:49.500176Z 1[Note] A temporary password is generated for root@localhost: ;%oAoQYYh3%t
修改密码
[root@mysql-0001 ~]# mysql -uroot -p';%oAoQYYh3%t'
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> alter user root@localhost identified by 'zzz-123-ZZZ';
Query OK, 0 rows affected (0.00 sec)
授权复制用户
mysql> grant replication slave on *.* to repluser@"%" identified by "zzz-123-ZZZ";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select user from mysql.user;
+---------------+
| user |
+---------------+
| repluser |
| mysql.session |
| mysql.sys |
| root |
+---------------+
4 rows in set (0.00 sec)
查看bin-log信息
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| mysql-0001.000002 | 685 | | | |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
配置MySQL-0002
安装MySQL
[root@mysql-0002 ~]# tar xf mysql-5.7.39-1.el7.x86_64.rpm-bundle.tar[root@mysql-0002 ~]# yum -y install *.rpm
[root@mysql-0002 ~]# grep "password" /var/log/mysqld.log | tail -12022-11-10T09:46:54.003213Z 1[Note] A temporary password is generated for root@localhost: se2oaiANhe-!
修改密码
[root@mysql-0002 ~]# mysql -uroot -p'se2oaiANhe-!'
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> alter user root@localhost identified by 'zzz-123-ZZZ';
Query OK, 0 rows affected (0.00 sec)
授权复制用户
mysql> grant replication slave on *.* to repluser@"%" identified by "zzz-123-ZZZ";
Query OK, 0 rows affected, 1 warning (0.00 sec)
查看bin-log信息
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| mysql-0002.000002 | 685 | | | |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
[root@mysql-0001 ~]# mysql -uroot -p'zzz-123-ZZZ'
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 4
Server version: 5.7.39-log MySQL Community Server (GPL)
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> change master to master_host="192.168.0.22",master_user="repluser",master_password="zzz-123-ZZZ",master_log_file="mysql-0002.000002",master_log_pos=685;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
[root@mysql-0002 ~]# mysql -uroot -p'zzz-123-ZZZ'
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 6
Server version: 5.7.39-log MySQL Community Server (GPL)
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> select * from mysql0001DB.m1;
+------+------+
| id | num |
+------+------+
| 11 | 22 |
| 33 | 44 |
+------+------+
2 rows in set (0.00 sec)
[root@mysql-0001 ~]# mysql -uroot -p'zzz-123-ZZZ'
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 7
Server version: 5.7.39-log MySQL Community Server (GPL)
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> select * from mysql0002DB.m2;
+------+------+
| id | top |
+------+------+
| 100 | 200 |
| 200 | 300 |
+------+------+
2 rows in set (0.00 sec)