一、部署步骤
1.检查centos自带MySQL,如果存在进行卸载
# rpm -qa | grep mariadb
# rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps
2.下载安装
# wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm # rpm -ivh mysql57-community-release-el7-9.noarch.rpm # yum install mysql-server
3.重启MySQL
# service mysqld restart
4.修改密码
# mysql -u root # use mysql mysql> update user set password=password("XXXX") where user="root"; mysql> flush privileges; mysql> exit; # service mysqld restart
5.远程链接设置
# mysql -u root -p mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mscyd@2019' WITH GRANT OPTION; mysql> exit; # service mysqld restart
6.启动、停止MySQL服务
# systemctl start mysqld # systemctl stop mysqld
7.检查MySQL运行状态
# systemctl status mysqld
8.防火墙设置
# firewall-cmd --zone=public --add-port=3306/tcp --permanent # firewall-cmd --reload # firewall-cmd --zone=public --query-port=3306/tcp
二、主从配置
1.主数据库配置
编辑配置文件
# vi /etc/my.cnf
在[mysqld]添加如下配置:
log-bin=mysql-bin server-id=1 binlog-ignore-db=information_schema binlog-ignore-db=performance_schema binlog-ignore-db=mysql binlog-do-db=mydb
注:mydb为配置的主从同步数据库
重启MySQL
# systemctl restart mysqld
查看配置
# mysql -u root -p mysql> show master status;
mysql> exit;
2.从数据库配置
编辑配置文件
# vi /etc/my.cnf
在[mysqld]添加如下配置:
log-bin=mysql-bin server-id=2 binlog-ignore-db=information_schema binlog-ignore-db=performance_schema binlog-ignore-db=mysql replicate-do-db=mydb replicate-ignore-db=mysql log-slave-updates slave-skip-errors=all slave-net-timeout=60
重启MySQL
# systemctl restart mysqld
修改配置
# mysql -u root -p mysql> show master status; mysql> stop slave; mysql>change master to master_host='192.168.18.70',master_user='root',master_password='XXXX',master_log_file='mysql-bin.000001', master_log_pos=120; mysql> start slave;
注:在这里指定Master的信息,master_log_file是在配置Master的时候的File选项, master_log_pos是在配置Master的Position 选项,这里要进行对应。
查看配置
mysql> show slave status G;
三、新建数据库测试
在主库上新建新建表和数据进行测试