1、從MYSQL官方下載MYSQL的源碼版本【一定要是源碼版本】
2、按以下代碼鍵入LINUX命令列
複製代碼 代碼如下:[注] 添加mysql組和使用者
#groupadd mysql
#useradd -g mysql mysql
[注] 解包到/usr/local
# tar -xzf mysql-standard-4.1.9-pc-linux-gnu-i686.tar.gz -C /usr/local
[注] 建立軟連結,方便操作(此處給此串連命名為mysql001,也可為其它的名字)
#cd /usr/local
#ln -s mysql-standard-5.0.15-linux-i686-glibc23 mysql001
#cd mysql001
#scripts/mysql_install_db
#chown -R root .
#chown -R mysql data
#chgrp -R mysql .
[注] 複製data,以供單版本多執行個體分配
#cp -a data data_1
#cp -a data data_2
[注] 添加多執行個體設定檔
#cd /usr/local/mysql001/bin
#cat >my_multi.cnf
[注] 以下是my_multi.cnf的配置資訊,可依此複製
[mysqld_multi]
mysqld = /usr/local/mysql001/bin/mysqld_safe
mysqladmin = /usr/local/mysql001/bin/mysqladmin
user = root
password = root
[mysqld1]
socket = /tmp/mysql_001.sock
port = 3301
pid-file = /usr/local/mysql001/data_1/hostname.pid
datadir = /usr/local/mysql001/data_1
log = /usr/local/mysql001/data_1/hostname.log
user = mysql
# slave setting
server-id = 2
master-host = 192.168.1.85
master-port = 3306
master-user = backup
master-password = 123456
replicate-do-db = gs_database
replicate-do-db = gs_log
master-connect-retry=30
[mysqld2]
socket = /tmp/mysql_5_2.sock
port = 3302
pid-file = /usr/local/mysql001/data_2/hostname.pid
datadir = /usr/local/mysql001/data_2
log = /usr/local/mysql001/data_2/hostname.log
user = mysql
# slave setting
server-id = 3
master-host = 192.168.1.69
master-port = 3306
master-user = backup
master-password = 123
replicate-do-db = gs_databaes
replicate-do-db = gs_log
master-connect-retry=30
CTRL+D退出。 複製代碼 代碼如下:#vi /etc/profile # 添加系統內容變數。
export MYSQL_HOME=/usr/local/mysql001/bin
export PATH=$PATH:$MYSQL_HOME
重啟系統讓環境變數生效。
添加至開機自動啟動【此處可不添加,依個人情況決定是否需要設定開機自動啟動】 複製代碼 代碼如下:vi /etc/rc.local
# 添加
mysqld_multi --defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf start 1,2
3、其它一些技巧
# 訪問某個執行個體:
mysql -u root -S /tmp/mysql_5_1.sock -p
# 設定各個執行個體密碼:
mysqladmin -u root password 'root' -S /tmp/mysql_5_1.sock
# 手動啟動各個執行個體:
mysqld_multi --defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf start 1,2
# 停止各個執行個體:
mysqld_multi --defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf stop 1,2
# 參考文章
http://blog.liuts.com/post/13/
由於第一次接觸LINUX,花了三天時間才算有所成就,發出來希望可以給大夥帶來方便