安装包下载地址:
https://downloads.mysql.com/archives/community/
1、 解压介质包:
# tar xf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz # mv mysql-8.0.30-linux-glibc2.12-x86_64 mysql # mkdir mysql/{data,logs}
2、 创建mysql用户,并对目录授权
# groupadd mysql # useradd -M -s /sbin/nologin -g mysql mysql # chown -R mysql.mysql mysql
3、编辑主从节点配置文件
以下为我的服务配置,可参考
master my.cnf
[mysqld] bind-address=0.0.0.0 port=3306 user=mysql basedir=/data/mysql datadir=/data/mysql/data log-error=/data/mysql/data/mysql.err socket=/tmp/mysql.sock pid-file=/data/mysql/data/mysql.pid server-id=1 slow_query_log=ON slow_query_log_file=/data/mysql/data/slow.log long_query_time=1 gtid_mode=ON enforce_gtid_consistency=ON binlog_format=row expire_logs_days=7 max_binlog_size=512M log-bin=/data/mysql/logs/mysql-bin log_bin_index=/data/mysql/logs/mysql-bin.index log-slave-updates = ON character-set-server = utf8 collation_server = utf8_general_ci default_authentication_plugin=mysql_native_password
slave my.cnf
[mysqld] bind-address=0.0.0.0 port=3306 user=mysql basedir=/data/mysql datadir=/data/mysql/data/ log-error=/data/mysql/data/mysql.err socket=/tmp/mysql.sock pid-file=/data/mysql/data/mysql.pid server-id=151 slow_query_log=ON slow_query_log_file=/data/mysql/data/slow.log long_query_time=1 gtid_mode = ON enforce_gtid_consistency = ON skip-slave-start = true expire_logs_days = 7 max_binlog_size = 512M read_only = ON log-bin=/data/mysql/logs/mysql-bin log_bin_index = /data/mysql/logs/mysql-bin.index relay-log = /data/mysql/logs/relay-log relay-log-index = /data/mysql/logs/relay-log-index relay-log-info-file = /data/mysql/logs/relay-log.info log-slave-updates=true master-info-repository = table relay-log-info-repository = table symbolic-links=0 character-set-server = utf8 collation_server = utf8_general_ci default_authentication_plugin=mysql_native_password
保存退出后记得修改权限
# chown mysql.mysql *
4、 初始化数据库
# cd /data/mysql # ./bin/mysqld --defaults-file=/data/mysql/my.cnf --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql –initialize
PS:mysql.err 日志中有初始化数据库密码
5、数据库启动
# ./bin/mysqld_safe --defaults-file=/data/mysql/my.cnf &
6、登录数据库修改初始密码,创建root@%账号并授权
mysql> alter user 'root'@'localhost' identified by 'Root~123'; mysql> create user 'root'@'%' identified WITH mysql_native_password by 'Root~123'; mysql> grant all privileges on *.* to 'root'@'%' with grant option;
7、 创建数据库同步账号并授权
mysql> create user 'repl'@'%' identified with mysql_native_password by 'repl'; mysql> grant replication slave on *.* to 'repl'@'%'; mysql> flush privileges;
8、配置主从同步,从库安装方法同上
登录主库查询Master状态,并记录 File 和 Position 的值:
mysql> show master;
登录从库操作:
mysql> CHANGE MASTER TO MASTER_HOST='73.134.64.72',MASTER_PORT=3306,MASTER_USER='repl',MASTER_PASSWORD='repl',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=2229; mysql> show slave status\G;
查询主从状态(参数 Slave_IO_Running 和 Slave_SQL_Running 是否都为yes,则证明配置成功。若为no,则需要查看对应的 Last_IO_Error 或 Last_SQL_Error 的异常值)
标签:bin,log,30,mysql8.0,mysql,MASTER,data,主从,logs From: https://www.cnblogs.com/goujinyang/p/17055577.html