1、下載安裝包
成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比侯馬網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式侯馬網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋侯馬地區(qū)。費用合理售后完善,10多年實體公司更值得信賴。
wget ?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、初始化數(shù)據(jù)庫
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
記住數(shù)據(jù)庫的隨機密碼
#關閉命令
bin/mysqladmin -u root -p? shutdown
#啟動命令
bin/mysqld_safe --user=mysql &
5、設置環(huán)境變量:
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狀態(tài)
7、為主從復制創(chuàng)建用戶
CREATE USER 'econage'@'%' IDENTIFIED BY 'hello123';? ?
GRANT REPLICATION SLAVE ON *.* TO econage@'%';
#mysql8 之前的版本中加密規(guī)則是mysql_native_password,而在mysql8之后,加密規(guī)則是caching_sha2_password,把mysql用戶登錄密碼加密規(guī)則還原成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', ??? ??? ??? ??? ?????????? #上面創(chuàng)建的用戶
? MASTER_PASSWORD='hello123',?? ??? ??? ? ??? #用戶密碼
? MASTER_LOG_FILE='master-bin.000002',?? ? #master的file文件名
? MASTER_LOG_POS=474;?? ??? ??? ??? ??? ??????????? # master的Position號
查看
show? slave? status\G????? #可能會狀態(tài)不對,執(zhí)行下面命令
stop? slave;
start? slave;
顯示兩個yes則正確。
10、驗證
#分別在master和slave查看
show?? databases;?????
#在master去創(chuàng)建一個庫
create? database? hello??
#會發(fā)現(xiàn)slave上也有一個hello的庫