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,花了三天時間才算有所成就,發出來希望可以給大伙帶來方便