MySQL8 -- 安装部署


wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

xz -d mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar

mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql-8.0.20

groupadd mysql
useradd -d /home/mysql -g mysql -m mysql
echo "mysql@123" | passwd --stdin mysql

yum install -y libaio

mkdir -p mysql-8.0.20/{binlog,log,run,data}
cp -r mysql-8.0.20/support-files/mysql.server /etc/init.d/mysqld

sed -i '/^basedir=/cbasedir=\/data\/mysql-8.0.20' /etc/init.d/mysqld
sed -i '/^datadir=/cdatadir=\/data\/mysql-8.0.20\/data' /etc/init.d/mysqld
sed -i '/^mysqld_pid_file_path=/cmysqld_pid_file_path=\/data\/mysql-8.0.20\/run\/mysql.pid' /etc/init.d/mysqld

chown -R mysql:mysql /data/mysql-8.0.20

/data/mysql-8.0.20/bin/mysqld --initialize --user=mysql --basedir=/data/mysql-8.0.20 --datadir=/data/mysql-8.0.20/data

./bin/mysql -uroot -p
d:Lu)q9tK3/b
WgwOjkL!a2!F
uMCT_um>J3xz

alter user 'root'@'localhost' identified by 'Passwd12#$';
alter user 'root'@'localhost' identified WITH mysql_native_password by 'Passwd12#$';
flush privileges;

create user 'root'@'%' identified by 'Passwd12#$';
grant all privileges on *.* to 'root'@'%' with grant option;
alter user 'root'@'%' identified WITH mysql_native_password by 'Passwd12#$';
flush privileges;

 


create user 'reply'@'%' identified by 'reply123';
grant replication slave on *.* to 'reply'@'%';
alter user 'reply'@'%' identified WITH mysql_native_password by 'reply123';
flush privileges;

create user 'reply'@'172.26.%' identified by 'reply123';
grant replication slave on *.* to 'reply'@'172.26.%';
flush privileges;

echo -e "alias mysql='mysql -S /data/mysql-8.0.20/run/mysql.sock'" >> ~mysql/.bashrc
echo -e "export MYSQL_HOME=/data/mysql-8.0.20" >> ~mysql/.bashrc
echo -e "export PATH=\$MYSQL_HOME/bin:\$PATH" >> ~mysql/.bashrc
source ~mysql/.bashrc

双主配置:
登录195从库:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000004 | 1572 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

登录224主库:
mysql> change master to master_host='172.26.170.195', master_port=31306, master_user='reply', master_password='reply123', master_log_file='mysql-bin.000011', master_log_pos=156, get_master_public_key=1;
mysql> start slave;
mysql> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 | 1059 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

登录195从库:
mysql> change master to master_host='172.26.98.224', master_port=31306, master_user='reply', master_password='reply123', master_log_file='mysql-bin.000007', master_log_pos=10312490, get_master_public_key=1;
mysql> start slave;
mysql> show slave status\G;


xtrabackup备份命令:
全量导出:
/mysql/percona-xtrabackup-8.0.12/bin/xtrabackup --user=root --password=Passwd12#$ --all-databases --backup --target-dir=/mysql/mysql_backup

导入:
xtrabackup --user=root --password=Passwd12#$ --datadir=/data/mysql-8.0.20/data/ --copy-back --target-dir=/data/mysql_backup

posted @ 2020-08-25 09:34  Ethan_x  阅读(109)  评论(0编辑  收藏  举报