Main server: Aliyun; Secondary server: Mac local server [preferably with the same primary and secondary database versions]

Configure /etc/mysql.conf.d on the primary server

[mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql log-error = /var/ log/mysql.error. Log log-bin = mysql.bin /var/ log/mysql.bin /var/ log/mysql.bin /var/ log/mysql.bin /var/ log/mysql.bin /var/ log/mysql.bin /var/ log/mysql.bin /var/ log/mysql.binCopy the code

Create database, user, grant permissions to user root

CREATE DATABASE IF NOT EXISTS test_db; CREATE USER 'test1'@'IP' IDENTIFIED BY 'test1'; GRANT ALL PRIVILEGES ON 'test_db'.* TO 'test1' @ '%' WITH GRANT OPTION; GRANT REPLICATION SLAVE ON *.* TO 'test1'@'%'; Create FLUSH PRIVILEGES; # refresh permissionCopy the code

Restart the mysql

service mysql restart

Example Query user test1 of mysql

  • File: mysql – bin. 000001
  • Position: 559

Mac slave server

Add configuration file my.cnf for MYSQL8.0

The mysql installation path is /usr/local/mysql

In /usr/etcmy.cnffile

[client] default-character-set = utf8 [mysqld] server-id = 2 [client] default-character-set = utf8 [mysqld] server-id = 2Copy the code

Restart the mysql

sudo /usr/local/mysql/support-files/mysql.server restart

Connect to slave. If enabled, suspend slave first

slave stop/start;

CHANGE MASTER TO CHANGE_HOST = 'IP', CHANGE_USER = 'test1', CHANGE_PASSWORD = 'password ', CHANGE_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 559;Copy the code

Check the connection status. Slave_ double YES indicates that the connection is successful

show slave status\G

  • Slave_IO_Running: YES

  • Slave_SQL_Running: YES

If both values are YES, the connection succeeds

Expand FAQ

1. The primary server is a cloud server, and no security group is configured.

2. The account password is incorrect.

3. Syntax for connecting to the server.

4. The mysql configuration file is faulty.

5. Primary server mysql permission;

6. The secondary database is not created.

Extended thinking can be master and slave to achieve the separation of reading and writing

Mysql > install mysql8Juejin. Cn/post / 701916…