yum -y remove mariadb
wget https:
yum -y install mysql80-community-release-el8-1.noarch.rpm
vim /etc/yum.repos.d/mysql-community.repo
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http:
enabled=0
gpgcheck=1
gpgkey=file:
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http:
enabled=1
gpgcheck=1
gpgkey=file:
yum -y install mysql-community-server
systemctl start mysqld
cat /var/log/mysqld.log | grep password
mysql -uroot -p
alter user 'root'@'localhost' identified by '123456';
# A 主
alter user 'root'@'localhost' identified by '123456';
# B 从
alter user 'root'@'localhost' identified by 'Zss@123!';
# 如果要远程登陆的话
GRANT ALL PRIVILEGES ON *.* TO 'slave'@'10.151.%.%' IDENTIFIED BY 'zss@!123S' WITH GRANT OPTION;
# A vim /etc/my.cnf
default-storage-engine=INNODB
symbolic-links=0
server_id=6
log_bin=/var/log/mysql/mysql-bin
# 修改主库的配置文件
# 创建日志存放文件夹 权限 重启数据库
mkdir -p /var/log/mysql
chown -R mysql.mysql /var/log/mysql
systemctl restart mysqld
# B vim /etc/my.cnf
default-storage-engine=INNODB
symbolic-links=0
server_id=7
log_bin=/var/log/mysql/mysql-bin
relay_log=/var/log/mysql/mysql-relay
# 修改从库的配置文件
# 创建日志存放文件夹 权限 重启数据库
mkdir -p /var/log/mysql
chown -R mysql.mysql /var/log/mysql
systemctl restart mysqld
# A
CREATE USER 'slave'@'10.151.%.%' IDENTIFIED BY 'zss@!123S';
select user,host from mysql.user;
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'10.151.%.%';
show grants for 'slave'@'10.151.%.%';
# 创建主从的用户 并给予权限
# B
mysql -h10.151.225.210 -uslave -p'zss@!123S'
# 远程登陆测试
# A
mysqldump -uroot -p --master-data --all-databases > backup.sql
scp backup.sql node2:~/
# 把主库数据同步到从库
# B
mysql -uroot -p < backup.sql
# 同步主库数据
mysql> change master to
-> master_host='10.151.225.210',
-> master_port=3306,
-> master_user='slave',
-> master_password='zss@!123S',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=360;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql>
mysql> start slave;
Query OK, 0 rows affected (0.03 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.151.225.210
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 360
Relay_Log_File: mysql-relay.000003
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 360
Relay_Log_Space: 523
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 6
Master_UUID: 068551a5-0783-11eb-a1ea-000c297cff7e
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
mysql> show databases;
+
| Database |
+
| information_schema |
| demo |
| mysql |
| performance_schema |
| sys |
| test |
| test_2020 |
| zss |
| zss01 |
+
9 rows in set (0.05 sec)
mysql> create database test_2030;
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> show databases;
+
| Database |
+
| information_schema |
| demo |
| mysql |
| performance_schema |
| sys |
| test |
| test_2020 |
| test_2030 |
| zss |
| zss01 |
+
10 rows in set (0.00 sec)
mysql>