Install & Config

Linux yum source

repo.mysql.com/yum/

Configuring the Extended Source

The RPM - the ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm

yum install mysql

yum install mysql-community-server -y

Start mysql and add it to the system

  • centos 7
systemctl start mysqld
systemctl stop mysqld
systemctl enable mysqld
Copy the code

Log in to the database using the initial password of mysql

Changing the Database Password

  • Example Change the default security policy level

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> setglobal validate_password_length=1; Query OK, 0 rows affected (0.01sec) mysql>set password for root@localhost = password('root'); Query OK, 0 rows affected (0.00 SEC) mysql>exit
Bye
[delores@localhost ~]$ mysql -uroot -proot
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 5
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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>
Copy the code

Setting up Remote Access

mysql> grant all on *.* to root@The '%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>
Copy the code

The source code to install

Docker install mysql image

Mac install mysql

Primary/secondary replication + Read/write separation

Primary/secondary replication is also called AB replication

Traditional mysql replication is a master-slave replication, which has one master, one or more slaves. After the master node commits and executes an item, it is sent (asynchronously) to the slave node via the IO thread on the slave node via bin-log. The bin-log is stored in the readly-log(relay log) of the slave node, which can be re-executed through the SQL thread (in statement-based replication) or applied (in row-based replication). When the slave node is connected to the master node, the location of the last synchronization is sent to the master node, and the master node sends the log file to the slave node

Read/write separation is based on master/slave replication!!

configuration

Master Node Configuration

/etc/my.cnf

Slave Node Configuration

Grant slave The server can synchronize the master

Grant replication slave, replication client on *.* to 'root'@'172.16.157.101(slave IP)' identified by 'root(slave PWD)'

mysql> grant replication slave.replication client on*. *to 'root'@'172.16.157.101' identified by 'root'; Query OK, 0 rows affected (0.00 SEC) mysql>select user,host from mysql.user;
+---------------+----------------+
| user          | host           |
+---------------+----------------+| root % | | | root | 172.16.157.101 | | mysql. The session | localhost | | mysql. The sys | localhost | | root | localhost | +---------------+----------------+
5 rows in set (0.00 sec)

mysql>
Copy the code

Checking master Status

show master status;

Slave Associates the master node

  • The slave node is displayed

  • Start binding

Change master to master_host='172.16.157.100', master_user='root', master_password='root', master_port=3306, master_log_file='mysql-bin.000002', master_log_pos=2079

Example Start primary/secondary replication

  • slave

start slave

View the master/slave synchronization status

show slave status\G

Troubleshoot problems

  • Due to mirror replication, the mysql uUID is the same, causing the startup failure
[delores@localhost ~]$ sudo find / -name 'auto.cnf'
[sudo] password forCNF [delores@localhost ~]$sudo vim /var/lib/mysql.auto. CNF Modify a uUID in the correct format restart slave: change master to ..... slave: start slaveCopy the code

test