1. 程式人生 > 其它 >mysql安裝及主從複製配置

mysql安裝及主從複製配置

一、安裝mysql8.0

##下載mysql安裝包 http://mirrors.sohu.com/mysql/MySQL-8.0/

  wget http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-client-8.0.18-1.el7.x86_64.rpm

  wget  http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-client-8.0.27-1.el7.x86_64.rpm

  wget  http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-common-8.0.27-1.el7.x86_64.rpm

  wget  http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-devel-8.0.27-1.el7.x86_64.rpm

  wget  http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-embedded-compat-8.0.27-1.el7.x86_64.rpm

  wget  http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-libs-8.0.27-1.el7.x86_64.rpm

  wget  http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-libs-compat-8.0.27-1.el7.x86_64.rpm

 wget  http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-server-8.0.27-1.el7.x86_64.rpm

 wget  http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm

##安裝mysql

#yum localinstall ./mysql-community-*

##啟動mysql

#systemctl start mysqld

##檢視初始密碼

##進入資料庫修改密碼

注意:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 提示密碼不符合規則。

二、mysql主從複製配置

#首先安裝mysql在主從服務節點安裝mysql資料庫,如上操作

#主庫配置

1##編輯配置檔案

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

port=3306

server-id=100   #設定server_id

gtid-mode=on   #啟用gtid,否則就是普通的複製架構

log-slave-updates  #slave更新是否計入日誌

enforce-gtid-consistency    #強制gtid的一致性

log_bin=/data/mysql/mybinlog

max_connections=500

2、建立主從複製專用使用者

#mysql -uroot -pWWW.123.com

>create user slave@192.168.1.% identified by ‘WWW.123.com’;

>grant replication slave on *.* to slave@192.168.1.%;

3、檢視主庫的日誌及偏移量

#從庫配置

1、編輯配置檔案my.cnf

2、進入mysql進行配置連線

#change master to master_host=’192.168.1.37’,master_user=’slave’,\

master_password=’WWW.123.com’,\

master_port=3306,master_auto_position=1;

3、檢視slave狀態,如下圖表示主從複製配置完成