mysql8解压方式安装
参照官方文档https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
1、解压安装包 mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
[root@localhost opt]# tar Jxvf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
2、移动到安装目录ll
[root@localhost opt]# mv mysql-8.0.17-linux-glibc2.12-x86_64 /usr/local/mysql
3、创建mysql用户和组
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql -s /bin/false mysql
4、创建mysql数据目录,修改权限
[root@localhost data]# mkdir mysql-files
[root@localhost data]# chown mysql:mysql mysql-files/
[root@localhost data]# chmod 750 mysql-files/
5、新建一个my-default.cnf文件,复制到/etc/my.cnf
[root@localhost mysql]# touch my-default.cnf
[root@localhost mysql]# chmod 755 my-default.cnf
[root@localhost mysql]# cp my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@localhost mysql]#
6、配置my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="\u@mysqldb \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
#skip-grant-tables
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql-files
socket = /tmp/mysql.sock
pid-file = mysqldb.pid
character-set-server = utf8mb4
default_authentication_plugin=mysql_native_password
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 6000
max_allowed_packet = 64M
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
log_timestamps = SYSTEM
slow_query_log_file = /data/mysql-files/slow.log
log-error = /data/mysql-files/error.log
server-id = 5
log-bin = /data/mysql-files/mysql-bin
log-bin-index = master-bin.index
relay-log=/data/mysql-files/relay-log
relay-log-index=relay-log.index
#主主复制
auto_increment_offset=1
auto_increment_increment=2
log-slave-updates=true
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
lower_case_table_names = 1
innodb_file_per_table = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
expire_logs_days = 30
binlog_format = row
binlog_checksum = 1
relay_log_recovery = 1
relay-log-purge = 1
[mysqldump]
quick
max_allowed_packet = 64M
7、配置环境变量,在/etc/profile后面追加
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/lib:$MYSQL_HOME/bin
刷新环境变量
[root@localhost mysql]# source /etc/profile
8、初始化mysql
[root@localhost mysql]# mysqld --initialize --user=mysql
[root@localhost mysql]# mysql_ssl_rsa_setup
9、启动mysql
[root@localhost mysql]# mysqld_safe --user=mysql &
8、设置开机自启动项,将/etc/init.d/mysql中的目录配置成与/etc/my.cnf一直
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server
[root@localhost mysql]# chmod +x /etc/init.d/mysql.server
[root@localhost mysql]# chkconfig --add mysql.server
[root@localhost mysql]# chkconfig --list
mysql.server 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
9、在mysql启动error.log中找到初始随机密码
2019-10-18T08:42:44.578537+08:00 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >1vhXn-RDeKn
用随机密码登录root用户,然后更改root用户密码为自己的密码
[root@localhost mysql-files]# mysql -uroot -p'>1vhXn-RDeKn'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.17
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@mysqldb 09:05: [(none)]> alter user root@localhost identified by 'root' ;
Query OK, 0 rows affected (0.03 sec)
root@mysqldb 09:06: [(none)]> exit
10、mysql服务启动、停止命令
[root@localhost mysql-files]# service mysql.server stop
Shutting down MySQL..2019-10-18T01:08:07.860416Z mysqld_safe mysqld from pid file /data/mysql-files/mysqldb.pid ended
SUCCESS!
[1]+ 完成 mysqld_safe --user=mysql(工作目录:/usr/local/mysql)
(当前工作目录:/data/mysql-files)
[root@localhost mysql-files]# ps -ef|grep mysql
root 8891 7304 0 09:08 pts/0 00:00:00 grep --color=auto mysql
[root@localhost mysql-files]# service mysql.server start
Starting MySQL.. SUCCESS!
11、开启3306端口
sudo /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
接上,主主复制的安装
1、创建主从账户
masterA上
root@mysqldb 11:41: [(none)]> create user 'repl'@'192.168.236.132' identified by '123456';
Query OK, 0 rows affected (0.02 sec)
root@mysqldb 14:10: [(none)]> ALTER USER 'repl'@'192.168.236.132' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
root@mysqldb 11:41: [(none)]> grant replication slave on *.* to 'repl'@'192.168.236.132';
Query OK, 0 rows affected (0.01 sec)
root@mysqldb 11:41: [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
root@mysqldb 14:02: [(none)]> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 456| | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
masterB上
root@mysqldb 13:16: [(none)]> create user 'repl'@'192.168.236.131' identified by '123456';
Query OK, 0 rows affected (0.04 sec)
root@mysqldb 14:12: [(none)]> ALTER USER 'repl'@'192.168.236.131' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
root@mysqldb 13:16: [(none)]> grant replication slave on *.* to 'repl'@'192.168.236.131';
Query OK, 0 rows affected (0.00 sec)
root@mysqldb 13:17: [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
root@mysqldb 14:04: [(none)]> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000004 | 1627 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
2、配置同步信息
masterA上
root@mysqldb 14:08: [(none)]> change master to master_host='192.168.236.132', master_port=3306, master_user='repl' , master_password='123456' , master_log_file='mysql-bin.000004', master_log_pos=1627;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
root@mysqldb 14:08: [(none)]> start slave;
Query OK, 0 rows affected (0.02 sec)
masterB上
root@mysqldb 14:13: [(none)]> change master to master_host='192.168.236.131', master_port=3306, master_user='repl' , master_password='123456' , master_log_file='mysql-bin.000003', master_log_pos=456;
Query OK, 0 rows affected, 2 warnings (0.03 sec)
root@mysqldb 14:15: [(none)]> start slave;
Query OK, 0 rows affected (0.02 sec)
检查masterA和masterB上同步状态
root@mysqldb 14:16: [(none)]> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
双机热备建立完毕