mysql安装及主从复制配置

蓝皮鼠 蓝皮鼠 | 106 | 2022-06-22

下载MySQL
官网下载地址:https://downloads.mysql.com/archives/community/

安装mysql

将mysql安装包上传到服务器
解压到 /usr/local 目录下

tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql
mv mysql /user/local/

配置环境变量

vim /etc/profile
增加 export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile

初始化

cd /usr/local/mysql
mysqld --initialize --user=mysql

将mysql添加到系统服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
chmod +x /etc/init.d/mysql.server
chkconfig --add mysql.server

修改配置文件

[mysqld]
port=3306
datadir=/usr/local/mysql/data
max_connections=200
max_connect_errors=10
character-set-server=utf8
default-storage-engine=INNODB
log-bin=mysql-bin
binlog-format=ROW
server_id=2 # 注意两台服务器不能一样就行
replicate-do-db=ry-cloud
log_slave_updates=1
slave_skip_errors=all
binlog-do-db=ry-cloud
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
sync_binlog=0
[mysql]
default-character-set=utf8
[client]
port=3306
default-character-set=utf8

启动mysql

service mysql.server start

进入mysql

mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '重置的密码';
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;

执行

set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

配置主从复制

主库 添加用户用来配置主从复 这个是主库服务器要加,双向同步,两台服务器都加上就行

CREATE USER canal IDENTIFIED BY 'canal';  
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
-- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;
FLUSH PRIVILEGES;

查看主库bin-log日志信息

show master status;

从库 更改连接主库的连接信息

change master to master_host='192.168.16.131',master_port=3306,master_user='canal',master_password='canal',master_log_file='mysql-bin.000003',master_log_pos=13168665;

从库 开启主从复制

start slave;

两台服务器镜像操作一下

文章标签: mysql
推荐指数:

真诚点赞 诚不我欺~

mysql安装及主从复制配置

点赞 收藏 评论