您好,登錄后才能下訂單哦!
1、下載安裝包
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18-el7-x86_64.tar.gz
rpm?-qa?|grep??mysql rpm?-qa?|grep?mariadb rpm?-e?--nodeps?mariadb-libs-5.5.60-1.el7_5.x86_64
3、修改配置文件
cat?/etc/my.cnf [mysql] default-character-set=utf8 [mysqld] skip-name-resolve port?=?3306 basedir=/usr/local/mysql datadir=/usr/local/mysql/data max_connections=200 character-set-server=utf8 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M log-bin=master-bin???????????#master是master-bin,slave的是slave-bin server-id=1???????????#master為1,slave2 gtid_mode=ON enforce_gtid_consistency=ON binlog_checksum=NONE
4、初始化數據庫
groupadd?mysql useradd?-r?-g?mysql?-s?/bin/false?mysql cd?/usr/local tar?xvf?mysql-8.0.18-el7-x86_64.tar.gz ln?-s?mysql-8.0.18-el7-x86_64?mysql cd?mysql mkdir?mysql-files chown?mysql:mysql?mysql-files chmod?750?mysql-files bin/mysqld?--initialize?--user=mysql bin/mysql_ssl_rsa_setup bin/mysqld_safe?--user=mysql?& cp?support-files/mysql.server?/etc/init.d/mysql.server
記住數據庫的隨機密碼
#關閉命令
bin/mysqladmin -u root -p? shutdown
#啟動命令
bin/mysqld_safe --user=mysql &
5、設置環境變量:
cat??/etc/profile.d/msyql MYSQL_HOME=/usr/local/mysql/ export?PATH=$PATH:$MYSQL_HOME/bin
6、修改隨機密碼:
mysql? -u root? -p??? ????????????????????????#輸入初始化隨機生成的密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'hello123';? ?
show master status;????? ????????? ? ? ? ? #查看master狀態
7、為主從復制創建用戶
CREATE USER 'econage'@'%' IDENTIFIED BY 'hello123';? ?
GRANT REPLICATION SLAVE ON *.* TO econage@'%';
#mysql8 之前的版本中加密規則是mysql_native_password,而在mysql8之后,加密規則是caching_sha2_password,把mysql用戶登錄密碼加密規則還原成mysql_native_password. 不然會報錯如下
#error connecting to master 'econage@192.168.0.56:3306' - retry-time: 60 retries: 1 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
ALTER USER 'econage'@'%' IDENTIFIED WITH mysql_native_password BY 'hello123';??? #添加這一條命令即可
FLUSH PRIVILEGES;
8、查看連接是否正確:
mysql?? -ueconage?? -phello123? -h292.168.0.56?? -e?? 'status;'
9、在slave進行連接master:
CHANGE MASTER TO
? MASTER_HOST='192.168.0.56',???????????? ????????#master主機ip
? MASTER_USER='econage', ??? ??? ??? ??? ?????????? #上面創建的用戶
? MASTER_PASSWORD='hello123',?? ??? ??? ? ??? #用戶密碼
? MASTER_LOG_FILE='master-bin.000002',?? ? #master的file文件名
? MASTER_LOG_POS=474;?? ??? ??? ??? ??? ??????????? # master的Position號
查看
show? slave? status\G????? #可能會狀態不對,執行下面命令
stop? slave;
start? slave;
10、驗證
#分別在master和slave查看
show?? databases;?????
#在master去創建一個庫
create? database? hello??
#會發現slave上也有一個hello的庫
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。