使用mysqld_multi實(shí)現(xiàn)單系統(tǒng)中配置多個(gè)MySQL服務(wù)器實(shí)例
來(lái)源:易賢網(wǎng) 閱讀:1118 次 日期:2014-10-14 10:05:34
溫馨提示:易賢網(wǎng)小編為您整理了“使用mysqld_multi實(shí)現(xiàn)單系統(tǒng)中配置多個(gè)MySQL服務(wù)器實(shí)例”,方便廣大網(wǎng)友查閱!

本文講利用MySQL源碼安裝MySQL并用mysqld_multi配置多實(shí)例。

1、下載MySQL源碼安裝版本

到MySQL官網(wǎng)查找到相應(yīng)版本下載,本文下載的是5.1版本

代碼如下:

wget -c ftp://ftp.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.1/mysql-5.1.60.tar.gz

2、解壓安裝

代碼如下:

tar -zxv -f mysql-5.1.60.tar.gz

./configure --prefix=/usr/local/mysql --with-charset=utf8

--with-extra-charset=all --enable-thread-safe-client --enable-assembler

--with-readline --with-big-tables

--with-named-curses-libs=/usr/lib/libncursesw.so.5

make && make install

3、添加用戶和用戶組

代碼如下:

groupadd mysql #添加mysql用戶組

useradd -g mysql mysql #創(chuàng)建mysql用戶并把它放到mysql組下

chown -R root:mysql /usr/local/mysql #修改mysql文件屬性

4、初始化數(shù)據(jù)目錄

代碼如下:

#把用到的工具添加到/usr/bin目錄

ln -s /usr/local/mysql/bin/mysqld_multi /usr/bin/mysqld_multi

ln -s /usr/local/mysql/bin/mysql_install_db /usr/bin/mysql_install_db

#初始化四個(gè)數(shù)據(jù)目錄

mysql_install_db --datadir=/usr/local/var/mysql1 --user=mysql

mysql_install_db --datadir=/usr/local/var/mysql2 --user=mysql

mysql_install_db --datadir=/usr/local/var/mysql3 --user=mysql

mysql_install_db --datadir=/usr/local/var/mysql4 --user=mysql

#修改屬性

chown -R mysql /usr/local/var/mysql1

chown -R mysql /usr/local/var/mysql2

chown -R mysql /usr/local/var/mysql3

chown -R mysql /usr/local/var/mysql4

5、配置多實(shí)例啟動(dòng)腳本

從MySQL的源碼中把復(fù)制到/etc/init.d/目錄下

代碼如下:

cp /usr/local/src/mysql-5.1.60/support-files/mysqld_multi.server /etc/init.d/mysqld_multi.server

#修改basedir和bindir為安裝路徑

basedir=/usr/local/mysql

bindir=/usr/local/mysql/bin

6、配置多實(shí)例數(shù)據(jù)庫(kù)配置文件

用mysqld_multi工具查看該配置文件的模板方法,命令為:mysqld_multi --example

在/etc/目錄下創(chuàng)建創(chuàng)建文件/etc/mysqld_multi.cnf,把mysqld_multi --example產(chǎn)生的文件粘進(jìn)去,修改相應(yīng)屬性,如:mysqld,mysqladmin,socket,port,pid-file,datadir,user等。

代碼如下:

[mysqld_multi]

mysqld = /usr/local/mysql/bin/mysqld_safe

mysqladmin = /usr/local/mysql/bin/mysqladmin

#user = mysql

#password = my_password

[mysqld1]

socket = /usr/local/var/mysql1/mysql1.sock

port = 3306

pid-file = /usr/local/var/mysql1/mysql1.pid

datadir = /usr/local/var/mysql1

#language = /usr/local/mysql/share/mysql/english

user = mysql

[mysqld2]

socket = /usr/local/var/mysql2/mysql2.sock

port = 3307

pid-file = /usr/local/var/mysql2/mysql2.pid

datadir = /usr/local/var/mysql2

#language = /usr/local/mysql/share/mysql/english

user = mysql

[mysqld3]

socket = /usr/local/var/mysql3/mysql3.sock

port = 3308

pid-file = /usr/local/var/mysql3/mysql3.pid

datadir = /usr/local/var/mysql3

#language = /usr/local/mysql/share/mysql/english

user = mysql

[mysqld4]

socket = /usr/local/var/mysql4/mysql4.sock

port = 3309

pid-file = /usr/local/var/mysql4/mysql4.pid

datadir = /usr/local/var/mysql4

#language = /usr/local/mysql/share/mysql/english

user = mysql

7、啟動(dòng)多實(shí)例數(shù)據(jù)庫(kù)

代碼如下:

將/usr/local/mysql/bin加到$PATH環(huán)境變量里

export PATH=/usr/local/mysql/bin:$PATH

#查看數(shù)據(jù)庫(kù)狀態(tài)

mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf report

#結(jié)果都為沒有運(yùn)行

Reporting MySQL servers

MySQL server from group: mysqld1 is not running

MySQL server from group: mysqld2 is not running

MySQL server from group: mysqld3 is not running

MySQL server from group: mysqld4 is not running

#啟動(dòng)

mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf start

#結(jié)果為

Reporting MySQL servers

MySQL server from group: mysqld1 is not running

MySQL server from group: mysqld2 is not running

MySQL server from group: mysqld3 is not running

MySQL server from group: mysqld4 is not running

#啟動(dòng)具體某一個(gè)實(shí)例可在start、stop后面加上具體數(shù)據(jù)1,2,3等

8、查看運(yùn)行結(jié)果

代碼如下:

#查看相應(yīng)端口是否已經(jīng)被監(jiān)聽

netstat -tunlp

#查看是否有活動(dòng)進(jìn)程

ps -aux|grep mysql

9、登錄相應(yīng)數(shù)據(jù)庫(kù)

代碼如下:

#進(jìn)入端口為3306的數(shù)據(jù)庫(kù)

mysql -uroot -p -h127.0.0.1 -P3306

#通過(guò)sock文件登錄

mysql -uroot -p -S /usr/local/var/mysql1/mysql1.sock

#查看socket文件

mysql> SHOW VARIABLES LIKE 'socket';

#查看pid文件

mysql> SHOW VARIABLES LIKE '%pid%';

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看數(shù)據(jù)庫(kù)
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)