成都网站建设设计

将想法与焦点和您一起共享

MySQL5.7.16gtid复制

《基础环境准备:》

十年的固阳网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整固阳建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“固阳网站设计”,“固阳网站推广”以来,每个客户项目都认真落实执行。

首先安装两台MySQL5.7.16数据库,安装如下步骤即可:

一、系统环境准备:

①:系统yum源配置:

[linux]

name=linux hae

baseurl=file:///media/

gpgcheck=1

gpgkey=file:///media/RPM-GPG-KEY-redhat-release

②:挂载Linux7.1系统盘安装必要的软件

yum -y install gcc* gcc-c++ ncurses ncurses-devel cmake bison libgcrypt perl

③:卸载系统自带的MySQL软件:

[root@localhost ~]# rpm -qa | grep maria*

[root@localhost ~]# rpm -qa | grep mysql

[root@localhost ~]# rpm -e --nodeps mariadb-server

[root@localhost ~]# rpm -e --nodeps mariadb

④:修改系统参数

[root@localhost ~]# vim /etc/security/limits.conf

*    soft    nproc     65535

*    hard    nproc     65535

*    soft    nofile    65535

*    hard    nofile    65535

[root@localhost ~]# vi /etc/profile

ulimit -u 65535

ulimit -n 65535

[root@localhost ~]# vim /etc/pam.d/login 

session    required     pam_limits.so

[root@localhost ~]# source /etc/profile

⑤:创建安装MySQL的必要目录

[root@localhost ~]# useradd mysql

[root@localhost ~]# passwd mysql

[root@localhost ~]# mkdir -p /mysql/mysql

[root@localhost ~]# mkdir -p /mysql/data

[root@localhost ~]# chown -R mysql.mysql /mysql

[root@localhost ~]# chmod -R 755 /mysql

二、开始安装MySQL5.7.16

①:解压MySQL软件

[mysql@localhost mysql]$ tar -zxvf boost_1_59_0.tar.gz 

[mysql@localhost mysql]$ tar -zxvf mysql-5.7.16.tar.gz 

②:编译MySQL5.7.16

[mysql@localhost mysql-5.7.16]$ cmake . -DCMAKE_INSTALL_PREFIX=/mysql/mysql \

 -DMYSQL_DATADIR=/mysql/data \

 -DDOWNLOAD_BOOST=1 \

 -DWITH_BOOST=/mysql/boost_1_59_0 

[mysql@localhost mysql-5.7.16]$ make -j 4

[mysql@localhost mysql-5.7.16]$ make install

③:初始化数据库

/mysql/mysql/bin/mysqld --initialize --user=mysql --basedir=/mysql/mysql/ --datadir=/mysql/data/

(初始化数据库后,会生成root用户的默认密码,要记住)

④:编辑my.cnf配置文件,启动数据库

[mysql@localhost data]$ vim my.cnf 

[client]

port = 3306

socket = /mysql/mysql/mysql.sock

default-character-set = utf8mb4

 

[mysqld]

port = 3306

socket = /mysql/mysql/mysql.sock

 

basedir = /mysql/mysql

datadir = /mysql/data

pid-file =/mysql/data/mysql.pid

user = mysql

bind-address = 0.0.0.0

server-id = 1       ------从库的编号可以设置 2   不能和主库一致;

 

init-connect = 'SET NAMES utf8mb4'

character-set-server = utf8mb4

 

back_log = 300

 

max_connections = 1000

max_connect_errors = 6000

open_files_limit = 65535

table_open_cache = 128

max_allowed_packet = 4M

binlog_cache_size = 1M

max_heap_table_size = 8M

tmp_table_size = 16M

 

read_buffer_size = 2M

read_rnd_buffer_size = 8M

sort_buffer_size = 8M

join_buffer_size = 8M

key_buffer_size = 4M

 

thread_cache_size = 8

 

query_cache_type = 1

query_cache_size = 8M

query_cache_limit = 2M

 

ft_min_word_len = 4

 

log_bin = mysql-bin

expire_logs_days = 30

 

log_error = /mysql/data/mysql-error.log

slow_query_log = 1

long_query_time = 1

slow_query_log_file = /mysql/data/mysql-slow.log

 

performance_schema = 0

explicit_defaults_for_timestamp

 

skip-external-locking

 

default_storage_engine = InnoDB

innodb_file_per_table = 1

innodb_open_files = 500

innodb_buffer_pool_size = 64M

innodb_write_io_threads = 4

innodb_read_io_threads = 4

innodb_thread_concurrency = 0

innodb_purge_threads = 1

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 2M

innodb_log_file_size = 32M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

 

bulk_insert_buffer_size = 8M

 

interactive_timeout = 28800

wait_timeout = 28800

 

[mysqldump]

quick

max_allowed_packet = 16M

 

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

启动MySQL数据库:

/mysql/mysql/bin/mysqld_safe --defaults-file=/mysql/data/my.cnf   &

⑤:启动数据库修改默认密码

[mysql@localhost ~]$ mysql -u root -p   (使用刚才的密码)

注意:如果提示密码过期不让登陆,可以在my.cnf配置文件加入:

[mysqld]

skip-grant-tables

然后重启MySQL,不用输入密码就可以登录数据库了!

最后修改默认密码:

mysql> update mysql.user set authentication_string=password('123456') where user='root' ; 

mysql> update mysql.user set password_expired='N';

mysql> flush privileges;

mysql> alter user 'root'@'localhost' identified by '123456';

mysql> flush privileges;

⑥:创建同步用用户(在主库)

mysql> grant replication slave,replication client on *.* to repl@'192.168.2.200' identified by 'feige';

###########################################################################

                      gtid 复制操作

一、主库操作

1、编辑主库的my.cnf配置文件,添加如下:

gtid-mode = on

enforce-gtid-consistency = 1 

binlog_format = row 

skip_slave_start=1

2、重新启动MySQL主库;

3、在主库创建测试用schema和表

mysql> create database zhang;

mysql> use zhang

mysql> show tables;

mysql> create table emp (id int);

mysql> insert into emp values (1);

mysql> show master status;

+------------------+----------+--------------+------------------+------------------------------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                        |

+------------------+----------+--------------+------------------+------------------------------------------+

| mysql-bin.000008 |      738 |              |                  | ac3842d2-ba9a-11e6-9e1b-000c298cd705:1-3 |

+------------------+----------+--------------+------------------+------------------------------------------+

注意:我们在主库开启了gtid复制,而且创建了测试用schema和表 并且查看状态可以得知目前的gtid号:1-3

二、从库操作:

1、编辑从库的my.cnf配置文件,添加如下:

gtid-mode = on

enforce-gtid-consistency = 1 

binlog_format = row 

skip_slave_start=1

2、重新启动MySQL主库;

3、配置主从同步:

mysql> CHANGE MASTER TO  MASTER_HOST='192.168.2.100', MASTER_USER='repl',  MASTER_PASSWORD='feige',   MASTER_PORT=3306,   MASTER_AUTO_POSITION = 1;

4、开启从库主从同步:

mysql> start slave;

5、开始验证主从同步状态:

注意:开启主从后,主库刚才创建的测试库和表都会复制过来,因为在主库开启gtid的时候 主库的每一步操作都会有个gtid号,等着从库开启同步后,会把所有记录的操作都会同步到从库;

注意:gtid复制 有很多限制:


本文标题:MySQL5.7.16gtid复制
文章起源:http://chengdu.cdxwcx.cn/article/ipgdoi.html