centos7 安装mysql 8.0.34 并配置主从
mkdir -p /data/mysql/data /data/mysql/log
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /data/mysql/
#/etc/my.cnf 配置文件
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
server-id = 1
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/mysql.pid
socket = /tmp/mysql.sock
tmpdir = /tmp
user = mysql
bind-address = 0.0.0.0
log_error=/data/mysql/log/mysql.log
#default_authentication_plugin=mysql_native_password
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
skip-external-locking
skip_name_resolve = 1
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
lower_case_table_names = 1
max_connections = 400
max_connect_errors = 1000
explicit_defaults_for_timestamp = true
max_allowed_packet = 128M
interactive_timeout = 1800
wait_timeout = 1800
tmp_table_size = 134217728
max_heap_table_size = 134217728
#expire_logs_days = 15
#初始化
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data/ --initialize
配置启动服务
vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=MySQL server
After=syslog.target network.target
[Service]
User=mysql
Group=mysql
Type=forking
TimeoutSec=0
#PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize
LimitNOFILE = 65535
Restart=on-failure
RestartSec=3
RestartPreventExitStatus=1
PrivateTmp=false
[Install]
WantedBy=multi-user.target
修改root密码
alter user 'root'@'localhost' identified by 'f6789affefdaM'
同步账号密码
create user 'slave'@'%' identified by '21dafefjj12da%';
grant replication slave on *.* to 'slave'@'%';
grant replication SLAVE, replication client ON *.* TO 'slave'@'%';
flush privileges;
从服务器登录后执行:
change master to get_master_public_key=1;
CHANGE MASTER TO MASTER_HOST='192.168.10.29', MASTER_USER='slave', MASTER_PASSWORD='21dafefjj12da%', MASTER_PORT=3306;
开启同步
start slave;
show slave status\;