1.源码下载地址
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.22.tar.gz
2.依赖包安装
yum -y install gcc gcc-c++ ncurses ncurses-devel make cmake git
groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql
mkdir -p /root/mysql/mysql
mkdir -p /root/mysql/data
mkdir -p /root/mysql/log
cd /root
chown -R mysql.mysql mysql/
cmake . -DCMAKE_INSTALL_PREFIX=/root/mysql/mysql -DMYSQL_DATADIR=/root/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root/src/mysql-5.7.22/boost -DSYCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOAL_INFILE=1 -DENABLE_DRACE=0 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EMBEDDED_SERVER=1
make & make install
vi /etc/my.cnf
[client]
port=3306
socket=/root/mysql/data/mysql.sock
default-character-set=utf8
[mysqld]
port=3306
user=mysql
socket=/root/mysql/data/mysql.sock
pid-file=/root/mysql/data/mysql.pid
basedir=/root/mysql/mysql
datadir=/root/mysql/data
tmpdir=/root/mysql/tmpdir
character-set-server=utf8
log_error=/root/mysql/log/mysql.err
server_id=2
log_bin=/root/mysql/log/binlog
general_log_file=/root/mysql/log/general_log
general_log=1
slow_query_log=ON
long_query_time=1
slow_query_log_file=/root/mysql/log/query_log
log_queries_not_using_indexes=ON
#######主主复制时主数据库要设置
log-slave-updates=1
#事务特性,最好设为1
sync_binlog=1
cd /root/mysql/mysql/bin
./mysqld --initialize-insecure --user=mysql --basedir=/root/mysql/mysql --datadir=/root/mysql/data
出现如下错误
bin/mysqld --initialize-insecure --user=mysql --basedir=/root/mysql/mysql --datadir=/root/mysql/data
mysqld: Can't change dir to '/root/mysql/data/' (Errcode: 13 - Permission denied)
2018-05-26T09:58:05.494660Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-05-26T09:58:05.669099Z 0 [ERROR] failed to set datadir to /root/mysql/data/
2018-05-26T09:58:05.669148Z 0 [ERROR] Aborting
解决方法:
chown -R mysql:mysql /root
GRANT REPLICATION SLAVE ON *.* to 'slave'@'172.17.0.%' identified by 'mypassword123';
change master to master_host='172.17.0.2',master_port=3306,master_user='slave',master_password='mypassword123',master_log_file='binlog.000005',master_log_pos=1045;
start slave; #启动slave
关闭SELinux
临时关闭:setenforce0
永久关闭
vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
设置后需要重启才能生效
创建帐号
授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";
grant create,select,insert,update on *.* to 'myuser'@'172.17.0.%' identified by "nihaomyuser";
flush privileges;