mysql5.7二进制安装以及GTID复制

mysql5.7二进制安装

解压缩文件

tar xvf mysql-5.7.26-el7-x86_64.tar.gz -C /usr/local/

创建用户mysql

useradd -r -s /bin/false mysql

创建软链接

ln -s mysql-5.7.26-el7-x86_64/ mysql

把客户端工具写到PATH变量里,然后执行使其生效

echo 'PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh

创建数据库存放路径,并修改权限

mkdir /data/mysql
chown -R mysql.mysql /data/mysql/

生成数据库文件,并生成root账号的随机口令密码

最后一行生成的密码一定要记录好

mysqld --initialize --user=mysql --datadir=/data/mysql
2020-07-07T05:30:52.338506Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-07T05:30:52.538668Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-07-07T05:30:52.570914Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-07-07T05:30:52.627204Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 060741c3-c013-11ea-ad8b-000c29bb3c32.
2020-07-07T05:30:52.628209Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-07-07T05:30:52.630471Z 1 [Note] A temporary password is generated for root@localhost: Rg6fgrxqhV=%

修改数据库配置文件,把路径修改,并删除多余选项

vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid

[client]
socket=/data/mysql/mysql.sock            

复制服务脚本,并添加到开机启动

cp mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysql start

修改初始密码,生产中建议密码复杂度设置高一些

mysqladmin -uroot -pRg6fgrxqhV=% password centos

登入数据库

mysql -pcentos

GTID复制

主服务器配置

vim /etc/my.cnf
[mysqld]
server-id=2
log-bin
gtid_mode=ON
#gtid模式开启
enforce_gtid_consistency
#保证GTID安全的参数


service mysqld restart

创建复制用账号

 grant replication salve on *.* to repluser@'192.168.160.%' identified by 'centos';

从服务器配置

vim /etc/my.cnf
[mysqld]
server-id=2
gtid_mode=ON
#gtid模式开启
enforce_gtid_consistency
#保证GTID安全的参数
CHANGE MASTER TO MASTER_HOST='192.168.160.129',
 MASTER_USER='repluser',
 MASTER_PASSWORD='centos',
 MASTER_PORT=3306,
 MASTER_AUTO_POSITION=1;

start slave;
©️2020 CSDN 皮肤主题: 游动-白 设计师: 上身试试 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值