Get the App
SLTechnology News&Howtos  ›  Database  › 

Linux binary package installation Mysql8 master-slave replication

Shulou Source: shulou.com Published: 2022-06-01 08:33:23 10月03日 Update

1. Download the installation package

Wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18-el7-x86_64.tar.gz

2. Delete the system with rpm-qa | grep mysqlrpm-qa | grep mariadbrpm-e-- nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

3. Modify the configuration file

Cat / etc/ my.cnf [MySQL] default-character-set=utf8 [mysqld] skip-name-resolveport = 3306basedir=/usr/local/mysqldatadir=/usr/local/mysql/datamax_connections=200character-set-server=utf8default-storage-engine=INNODBlower_case_table_names=1max_allowed_packet=16Mlog-bin=master-bin # master is master-bin,slave is the slave-binserver-id=1 # master for the first slave2gtidhands modepieces for one for cephalopause gtidholders considering one Nbinlogically checksummed none

4. Initialize the database

Groupadd mysqluseradd-r-g mysql- s / bin/false mysqlcd / usr/localtar xvf mysql-8.0.18-el7-x86_64.tar.gzln-s mysql-8.0.18-el7-x86_64 mysqlcd mysqlmkdir mysql-fileschown mysql:mysql mysql-fileschmod 750mysql-filesbin/mysqld-initialize-user=mysqlbin/mysql_ssl_rsa_setupbin/mysqld_safe-user=mysql & cp support-files/mysql.server / etc/init.d/mysql.server

Remember the random password of the database

# close command

Bin/mysqladmin-u root-p shutdown

# start command

Bin/mysqld_safe-- user=mysql &

5. Set environment variables:

Cat / etc/profile.d/msyqlMYSQL_HOME=/usr/local/mysql/export PATH=$PATH:$MYSQL_HOME/bin

6. Modify the random password:

Mysql-u root-p # enter the password that initializes the randomly generated

ALTER USER 'root'@'localhost' IDENTIFIED BY' hello123'

Show master status; # View master status

7. Create a user for master-slave replication

CREATE USER 'econage'@'%' IDENTIFIED BY' hello123'

GRANT REPLICATION SLAVE ON *. * TO econage@'%'

In the previous version of # mysql8, the encryption rule is mysql_native_password, but after mysql8, the encryption rule is caching_sha2_password, which restores the mysql login password encryption rule to mysql_native_password. Otherwise, the error will be reported as follows

# error connecting to master 'econage@192.168.0.56:3306'-retry-time: 60 retries: 1 message: Authentication plugin' caching_sha2_password' reported error: Authentication requires secure connection.

ALTER USER 'econage'@'%' IDENTIFIED WITH mysql_native_password BY' hello123'; # just add this command

FLUSH PRIVILEGES

8. Check whether the connection is correct:

Mysql-ueconage-phello123-h292.168.0.56-e 'status;'

9. Connect to master in slave:

CHANGE MASTER TO

MASTER_HOST='192.168.0.56', # master Host ip

MASTER_USER='econage', # users created above

MASTER_PASSWORD='hello123', # user password

File file name of MASTER_LOG_FILE='master-bin.000002', # master

Position number of MASTER_LOG_POS=474; # master

View

Show slave status\ G # may be in the wrong state, execute the following command

Stop slave

Start slave

The display of two yes is correct.

10. Verification

# check it in master and slave respectively

Show databases

# create a library in master

Create database hello

# you will find that there is also a library of hello on slave

Tags: Password command user rule encryption data database file status master and slave no two host variable file name version environment system will report generate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Huawei Docker NVidia macOS