1、部署MySQL数据库
1.1、上传安装所需包,创建用户,创建目录,安装依赖
所需包:MySQL :: Download MySQL Community Server (Archived Versions)
sudo yum install perl perl-Getopt-Long perl-strict
useradd mysql
echo "****" | passwd --stdin mysql
su - mysql
mkdir /data1/mysqld/data
1.2、安装mysql,创建log目录
tar -xvf mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
rpm -ivh mysql-community-common-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.36-1.el7.x86_64.rpm
mkdir /data1/mysqld/log && chown mysql:mysql /data1/mysqld/log -R
1.3、修改配置文件
vi /etc/my.cnf
port=3306
log-bin=mysql-bin
datadir=/data/mysqld/data
log-error=/data/mysqld/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character_set_server=utf8
init_connect='SET NAMES utf8'
log-bin=/data1/mysqld/log/mysql-bin
server-id=1
max_binlog_size=1GB
expire_logs_days=5
1.4、启动并登录
systemctl start mysqld.service
cat /data1/mysqld/log/mysqld.log | grep password
mysql -u**** -p****
1.5、创建远程登录,修改密码
flush privileges;
grant all privileges on *.* to '****'@'%' identified by '****' with grant option;
set password for ****@localhost = password('****');
****
1.6、配备MySQL主从
(主库配置)
#SHOW VARIABLES LIKE 'log_bin';查看bin-log是否为ON,不为on则未开启binlog日志
show master status\G
#创建主从同步的授权账号密码并刷新;
grant all on *.* to '****'@'%' identified by '****';
flush privileges;
(从库配置)
vim /etc/my.cnf
server-id=2
systemctl restart mysqld.server
1.7、进入mysql配置
\e
CHANGE MASTER TO
MASTER_HOST='*.*.*.*',
MASTER_USER='****',
MASTER_PASSWORD='****',
MASTER_LOG_FILE='mysql-bin.00000*',
MASTER_LOG_POS=***;
1.8、启动主从
start slave;
#可通过show slave status\G检测主从是否为双yes。