使用的包
mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
可能需要清理的包
yum remove -y mariadb-libs
安装
tar -xf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
ln -s /usr/local/mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
#将数据放在/var/local/mysql/data下
#将日志放在/var/log/mysql下
#将pid文件和socker文件放在/var/local/mysql下
mkdir -p /var/local/mysql/data /var/log/mysql/bin-log
useradd -rs /bin/false mysql
chown -R mysql. /var/local/mysql /var/log/mysql
#从库还需要
mkdir /var/log/mysql/relay-log
chown mysql. /var/log/mysql/relay-log
主库/etc/my.cnf
[mysqld]
#常规选项
server_id=51
character-set-server=utf8
collation-server=utf8_general_ci
default_storage_engine=InnoDB
datadir=/var/local/mysql/data
socket=/dev/shm/mysql.sock
#这个参数很奇怪,不想别的参数,不区分-和_,这里只能写成pid-file
pid-file=/var/local/mysql/mysql.pid
port=3306
log_error=/var/log/mysql/mysqld_err.log
user=mysql
lower_case_table_names=1
secure_file_priv=/var/local/mysql
#InnoDB相关
innodb_file_per_table=1
#双一选项之一
innodb_flush_log_at_trx_commit=1
#binlog相关
log_bin=/var/log/mysql/bin-log/binlog
binlog_format=ROW
expire_logs_days=8
#双一选项之一
sync_binlog=1
#gtid相关
gtid_mode=on
enforce_gtid_consistency=1
#慢查询相关
slow_query_log=1
slow_query_log_file=/var/log/mysql/slow_sql.log
long_query_time=0.1
log_queries_not_using_indexes=1
[mysql]
socket=/dev/shm/mysql.sock
prompt=\h:[\\U\\_\\d]>\\_
从库/etc/my.cnf
[mysqld]
#常规选项
server_id=58
character-set-server=utf8
collation-server=utf8_general_ci
default_storage_engine=InnoDB
datadir=/var/local/mysql/data
socket=/dev/shm/mysql.sock
pid-file=/var/local/mysql/mysql.pid
port=3306
log_error=/var/log/mysql/mysqld_err.log
user=mysql
lower_case_table_names=1
secure_file_priv=/var/local/mysql
#从库只读
read_only=1
super_read_only=1
#为保证slave recovery,
#给出
#sync_binlog=1
#relay_log_recovery=1
#MASTER_AUTO_POSITION=1
#指定master.info和relay-log.info路径
master_info_file=/var/log/mysql/master.info
relay_log_info_file=/var/log/mysql/relay-log.info
#relay_log_info_repository=TABLE
#指定relay-log文件路径
relay_log=/var/log/mysql/relay-log/relaylog
#故障日志恢复相关
relay_log_recovery=1
#MHA相关
relay_log_purge=0
#InnoDB相关
innodb_file_per_table=1
#双一选项之一
innodb_flush_log_at_trx_commit=1
#binlog相关
#默认情况下,从库不再记录复制主库的SQL的binlog了,
#这个配置项置为1,记录从主库来的SQL的binlog
#log_slave_updates=1
log_bin=/var/log/mysql/bin-log/binlog
binlog_format=row
expire_logs_days=8
#双一选项之一
sync_binlog=1
#gtid相关
gtid_mode=on
enforce_gtid_consistency=1
#慢查询相关
slow_query_log=1
slow_query_log_file=/var/log/mysql/slow_sql.log
long_query_time=0.1
log_queries_not_using_indexes=1
[mysql]
socket=/dev/shm/mysql.sock
prompt=\h:[\\U\\_\\d]>\\_
执行初始化程序
cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/
#编辑启动脚本
vim /etc/init.d/mysql.server
#basedir=/usr/local/mysql
#datadir=/var/local/mysql/data
bin/mysqld --initialize-insecure
service mysql.server start
chkconfig --add mysql.server
chkconfig mysql.server on
#从库需要将`/etc/my.cnf`中的`super_read_only=1`注释掉
bin/mysql_secure_installation
#从库需要将`/etc/my.cnf`中的`super_read_only=1`取消注释
配置alias
vim ~/.bashrc
alias mysql='/usr/local/mysql/bin/mysql -p'
alias mysqldump='/usr/local/mysql/bin/mysqldump'
alias mysqlbinlog='/usr/local/mysql/bin/mysqlbinlog'
source ~/.bashrc
参考文档
Section 16.2.4.2 Slave Status Logs
Section 16.3.2 Handling an Unexpected Halt of a Replication Slave