MYSQL 多實(shí)例運(yùn)行 mysql可以以多實(shí)例的方式,實(shí)現(xiàn)一臺(tái)服務(wù)器,運(yùn)行在不同端口不同數(shù)據(jù)文件的mysql,它們是相互獨(dú)立的。 1、關(guān)閉原有的默認(rèn)端口3306的mysql:service mysqd stop 2、拷貝或創(chuàng)建數(shù)據(jù)文件 ? #拷貝現(xiàn)有的mysql數(shù)據(jù)庫(kù)文件#我的在/var/lib/mysql,拷
MYSQL 多實(shí)例運(yùn)行mysql可以以多實(shí)例的方式,實(shí)現(xiàn)一臺(tái)服務(wù)器,運(yùn)行在不同端口不同數(shù)據(jù)文件的mysql,它們是相互獨(dú)立的。
1、關(guān)閉原有的默認(rèn)端口3306的mysql:service mysqd stop
2、拷貝或創(chuàng)建數(shù)據(jù)文件
?
#拷貝現(xiàn)有的mysql數(shù)據(jù)庫(kù)文件 #我的在/var/lib/mysql,拷貝一份至mysql_3307文件夾 [root@test-206 ~]# cp -r /var/lib/mysql /var/lib/mysql_3307
?
#創(chuàng)建一個(gè)新的空數(shù)據(jù)庫(kù) [root@test-206 ~]# mkdir /var/lib/mysql_3307 [root@test-206 ~]# mysql_install_db --datadir=/var/lib/mysql_3307 --user=mysql
?3、給數(shù)據(jù)文件賦予mysql用戶與用戶組
[root@test-206 ~]# chown -R mysql.mysql /var/lib/mysql_3307
?4、創(chuàng)建multi的配置cnf文件,用于啟動(dòng)這個(gè)mysql實(shí)例(如3307)載入執(zhí)行
[root@test-206 ~]# touch /usr/local/my_multi.cnf
?文件中寫入你想要的配置,如下為典型配置
[mysqld_multi] mysqld = /usr/bin/mysqld_safe mysqladmin = /usr/bin/mysqladmin user = root #用于登陸和關(guān)閉此服務(wù) password = 123456 #同上 [mysqld3307] socket = /tmp/mysql_3307.sock port = 3307 pid-file = /var/lib/mysql_3307/3307.pid datadir = /var/lib/mysql_3307/ log = /var/lib/mysql_3307/3307.log character-set-server = utf8 user = mysql
?5、啟動(dòng)你的多實(shí)例
[root@test-206 ~]# mysqld_multi --defaults-extra-file=/usr/local/my_multi.cnf start 3307
?6、檢查是否啟動(dòng)成功
[root@test-206 ~]# netstat -ntlp tcp 0 0 :::3306 :::* LISTEN 3919/mysqld tcp 0 0 :::3307 :::* LISTEN 15027/mysqld
?
如果沒(méi)有發(fā)現(xiàn)你要的端口號(hào)mysql實(shí)例,可以檢查下/var/lib/mysql_3307/3307.log文件,排除問(wèn)題
7、設(shè)置新的密碼
[root@test-206 ~]# mysqladmin -uroot -S /tmp/mysql_3307.sock password 123456
?8、登入你的新實(shí)例
[root@test-206 ~]# mysql -uroot -S /tmp/mysql_3307.sock -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.20-log Distributed by The IUS Community Project Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
?再次確認(rèn)下,你的這個(gè)實(shí)例,是不是用的mysql_3307這個(gè)文件夾的數(shù)據(jù)
mysql> show variables like '%datadir%'; +---------------+----------------------+ | Variable_name | Value | +---------------+----------------------+ | datadir | /var/lib/mysql_3307/ | +---------------+----------------------+ row in set (0.00 sec) mysql>
?恩,沒(méi)有錯(cuò)!最后,搞搞權(quán)限、用戶之類。收工!
#查用戶 mysql> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | test-206 | | root | test-206 | +------+-----------+ rows in set (0.00 sec) #設(shè)權(quán)限 mysql> grant all on *.* to root@'%' identified by 'root' with grant option; Query OK, 0 rows affected (0.00 sec) ##查權(quán)限 mysql> show grants for root; ##創(chuàng)用戶 mysql> grant select on *.* to backup@'%' identified by 'backup'; Query OK, 0 rows affected (0.00 sec)
?
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com