centos7下快速安裝MySQL CentOS 7的yum源中貌似沒(méi)有正常安裝MySQL時(shí)的mysql-sever文件,需要去官網(wǎng)上下載
#wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm#rpm -ivh mysql-community-release-el7-5.noarch.rpm #yum install mysql-community-server成功安裝之后重啟mysql服務(wù)
1
# service mysqld restart初次安裝mysql是root賬戶是沒(méi)有密碼的 設(shè)置密碼的方法
# mysql -urootmysql> set passWord for root@localhost=password('mypasswd');mysql> exit搞定!
打開(kāi)3306端口
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT/etc/rc.d/init.d/iptables save#修改生效/etc/init.d/iptables status#查看配置權(quán)連接mysql開(kāi)啟MYSQL遠(yuǎn)程訪問(wèn)權(quán)限語(yǔ)法:grant [權(quán)限] on [數(shù)據(jù)庫(kù)名].[表名] to ['用戶名']@['web服務(wù)器的ip地址'] identified by ['密碼'];grant all on *.* to 'root'@'%' identified by 'root';或者指定IP地址grant all on *.* to 'root'@'192.168.1.103' identified by 'root';登錄mysql –uroot –pmypasswd導(dǎo)入數(shù)據(jù)庫(kù)文件,根據(jù)條件加上文件的路徑,以下這種情況是在文件所在的文件夾下打開(kāi)終端mysql>source jtdb.sql;mysql>use jtdb;mysql>set names utf8; #防止亂碼在第二臺(tái)服務(wù)器上安裝mysql,方法同上
配置主服務(wù)器:
編輯主master服務(wù)器配置文件
vim /etc/my.cnf在[mysqld]節(jié)點(diǎn)下加入兩句話
server-id=1log-bin=mysql-bin #啟用二進(jìn)制日志重啟服務(wù):service mysql restart 登錄mysql:mysql –uroot -PRoot mysql>flush tables with read lock; #數(shù)據(jù)庫(kù)鎖表,不讓寫(xiě)數(shù)據(jù) mysql>show master status; #查看MASTER狀態(tài)(這兩個(gè)值File和Position) 
從啟動(dòng)好后,記得要解除鎖定
mysql>unlock tables;配置從服務(wù)器 修改UUID
由于data拷貝是全目錄拷貝,將/var/lib/mysql/auto.cnf也拷貝,它里面記錄了對(duì)數(shù)據(jù)庫(kù)的一個(gè)uuid標(biāo)識(shí),隨便產(chǎn)生個(gè)新的uuid,替換掉新目錄中的auto.cnf中的uuid串即可。可以用select uuid()來(lái)產(chǎn)生新值,手工黏貼到auto.cnf文件中。修改/etc/my.cnf增加一行
server-id=2重啟服務(wù) service mysql restart 通過(guò)mysql命令配置同步日志的指向:
change master to master_host='192.168.58.130',master_port=3306,master_user='root',master_password='007617',master_log_file='mysql-bin.000003',master_log_pos=120;master_host 主服務(wù)器的IP地址 master_port 主服務(wù)器的PORT端口 master_log_file 和主服務(wù)器show master status中的File字段值相同 master_log_pos 和主服務(wù)器show master status中的Position字段值相同
start slave; #stop slave;停止服務(wù),出錯(cuò)時(shí)先停止,再重新配置 show slave status/G; #查看SLAVE狀態(tài),/G結(jié)果縱向顯示。必須大寫(xiě). 只有出現(xiàn)兩個(gè)yes才算成功。 注意:如果出錯(cuò),可以看后面的錯(cuò)誤信息。觀察Slave_SQL_Running_State字段,它會(huì)記錄詳細(xì)的錯(cuò)誤信息。如果正常,上面兩個(gè)線程執(zhí)行都應(yīng)該是YES。這樣當(dāng)主庫(kù)創(chuàng)建數(shù)據(jù)庫(kù)、創(chuàng)建表、插入數(shù)據(jù)時(shí),從庫(kù)都會(huì)立刻同步,這樣就實(shí)現(xiàn)了主從復(fù)制。

service mysql restart #重啟服務(wù)
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注