1、依赖安装
yum install -y gcc gcc-c++ cmake ncurses ncurses-devel bison
yum install -y krb5 krb5-devel libidn libidn-devel openssl openssl-devel -y
2、创建用户
useradd -s /sbin/nologin mysql
mkdir -p /data/mysql/data
chown -R mysql:mysql /data/mysql
3、解压包
tar -zxvf mysql-boost-5.7.28.tar.gz
4、编译安装
cd mysql-boost-5.7.28
cmake -DWITH_BOOST=boost -DCMAKE_INSTALL_PREFIX=/data/mysql -DMYSQL_DATADIR=/data/mysql/data -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DMYSQL_USER=mysql -DWITH_ZLIB=bundled -DWITH_READLINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0 -DWITH_SSL=system
make && make install
5、创建配置文件/etc/my.cnf
5.1、主MySQL配置
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
user = mysql
basedir = /data/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/mysql.pid
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1024M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M
performance_schema_max_table_instances = 1000
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log_bin=mysql-bin
binlog_format=mixed
server_id = 232
expire_logs_days = 10
early-plugin-load = ""
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
character_set_server=utf8
init_connect='SET NAMES utf8'
# mysql master slave
# 标识
server-id = 1
#此参数表示启用binlog并指定日志文件路径
log_bin=master-bin
#此参数指定二进制索引文件路径
log_bin_index=master-bin.index
#配置记录binlog日志的数据库,有binlog日志的数据库会被同步,多个数据库用逗号隔开
binlog_do_db=binlog_db
binlog_format = ROW
# 忽略不被同步
binlog_ignore_db=information_schema
binlog_ignore_db=performation_schema
binlog_ignore_db=sys
binlog_ignore_db=mysql
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M
5.2、从配置
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
user = mysql
basedir = /data/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/mysql.pid
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1024M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M
performance_schema_max_table_instances = 1000
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log_bin=mysql-bin
binlog_format=mixed
server_id = 232
expire_logs_days = 10
early-plugin-load = ""
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
character_set_server=utf8
init_connect='SET NAMES utf8'
# mysql master slave
# 标识
server-id = 2
#启动中继日志服务并设置地址,中继日志就是存储主库过来的binlog日志
relay-log = slave-relay-bin
#中继日志二进制文件索引地址
relay-log-index = slave-relay-bin.index
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M
6、初始化数据库(主从都需要配置,默认root密码为空,根据实际需求修改root密码)
./mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
7、在主库创建授权远程连接用户
mysql>
CREATE USER
'rep1'
@
'%'
IDENTIFIED BY
'123456'
; Query OK, 0 rows affected (0.01 sec)
mysql>
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO
'rep1'
@
'%'
; Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+-------------------+----------+--------------+--------------------------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+--------------------------------------------------+-------------------+
| master-bin.000001 | 398 | binlog_db | information_schema,performation_schema,sys,mysql | |
+-------------------+----------+--------------+--------------------------------------------------+-------------------+
1 row in set (0.00 sec)
8、从库连接mysql主数据库,登陆到从库上执行
mysql> change master to master_host='主库ip地址', master_port=3306, master_user='repl', master_password='123456', master_log_file='master-bin.000001
', master_log_pos=398
;
mysql> start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 主库IP
Master_User: rep1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 398
Relay_Log_File: slave-relay-bin.000002
Relay_Log_Pos: 565
Relay_Master_Log_File: master-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 398
Relay_Log_Space: 772
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: cb1feb21-28bb-11eb-aace-000c29ac7a88
Master_Info_File: /data/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified