Linux binaries installed Mysql8 master-slave replication

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 comes

rpm -qa |grep  mysql
rpm -qa |grep mariadb
rpm -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-resolve
port = 3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
log-bin=master-bin           #master是master-bin,slave的是slave-bin
server-id=1           #master为1,slave2
gtid_mode=ON
enforce_gtid_consistency=ON
binlog_checksum=NONE

4, initialize the database

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar xvf mysql-8.0.18-el7-x86_64.tar.gz
ln -s mysql-8.0.18-el7-x86_64 mysql
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysql.server

Remember random password for the databaseimage-20191226160516781.png

# Close the command

bin/mysqladmin -u root -p  shutdown

# Start command

bin/mysqld_safe --user=mysql &


5, set the environment variable:

cat  /etc/profile.d/msyql

MYSQL_HOME=/usr/local/mysql/
export PATH=$PATH:$MYSQL_HOME/bin

6, modified random password:

mysql -u root -p # input initialized randomly generated passwords

ALTER USER 'root'@'localhost' IDENTIFIED BY 'hello123';   
show master status;                        #查看master状态

image-20191226161712968.png

7, mainly to create a user from copying

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

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


# Mysql8 in versions prior to encryption rule is mysql_native_password, and after mysql8, encryption rules are caching_sha2_password, the mysql user password encryption rule reduced to mysql_native_password. Or will be given as follows

#error connecting to master '[email protected]: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'; # add this single command

FLUSH PRIVILEGES;

8, view the connection is correct:

mysql   -ueconage   -phello123  -h192.168.0.56   -e   'status;'

image-20191226172818003.png

9, in connection master Slave :

The TO MASTER the CHANGE
  MASTER_HOST = '192.168.0.56', #MASTER host ip
  MASTER_USER = 'econage', created above # user
  MASTER_PASSWORD = 'hello123', # user password
  MASTER_LOG_FILE = 'master-bin.000002', #master of file documents name
  MASTER_LOG_POS = 474; # master of Position No.

View

show slave status \ G # may not state, execute the following command
STOP Slave;
Start Slave;

image-20191226201513037.png

Yes the two display correctly.

10, verification

# View respectively in the master and slave

show   databases;     

# In the master to create a library

create  database  hello  

#'Ll find on the slave also has a library hello

Guess you like

Origin blog.51cto.com/14268033/2462236