應用mysqld_multi完成單體系中設置裝備擺設多個MySQL辦事器實例。本站提示廣大學習愛好者:(應用mysqld_multi完成單體系中設置裝備擺設多個MySQL辦事器實例)文章只能為提供參考,不一定能成為您想要的結果。以下是應用mysqld_multi完成單體系中設置裝備擺設多個MySQL辦事器實例正文
本文講應用MySQL源碼裝置MySQL並用mysqld_multi設置裝備擺設多實例。
1、下載MySQL源碼裝置版本
到MySQL官網查找到響應版本下載,本文下載的是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 #創立mysql用戶並把它放到mysql組下
chown -R root:mysql /usr/local/mysql #修正mysql文件屬性
4、初始化數據目次
#把用到的對象添加到/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
#初始化四個數據目次
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、設置裝備擺設多實例啟動劇本
從MySQL的源碼中把復制到/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、設置裝備擺設多實例數據庫設置裝備擺設文件
用mysqld_multi對象檢查該設置裝備擺設文件的模板辦法,敕令為:mysqld_multi --example
在/etc/目次下創立創立文件/etc/mysqld_multi.cnf,把mysqld_multi --example發生的文件粘出來,修正響應屬性,如: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、啟動多實例數據庫
將/usr/local/mysql/bin加到$PATH情況變量裡
export PATH=/usr/local/mysql/bin:$PATH
#檢查數據庫狀況
mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf report
#成果都為沒有運轉
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
#啟動
mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf start
#成果為
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
#啟動詳細某一個實例可在start、stop前面加上詳細數據1,2,3等
8、檢查運轉成果
#檢查響應端口能否曾經被監聽
netstat -tunlp
#檢查能否有運動過程
ps -aux|grep mysql
9、登錄像應數據庫
#進入端口為3306的數據庫
mysql -uroot -p -h127.0.0.1 -P3306
#經由過程sock文件登錄
mysql -uroot -p -S /usr/local/var/mysql1/mysql1.sock
#檢查socket文件
mysql> SHOW VARIABLES LIKE 'socket';
#檢查pid文件
mysql> SHOW VARIABLES LIKE '%pid%';