Linux下安裝啟動多個Mysql
網上找了N多資料,沒有一個可以順利成功的,郁悶,可能是水平有限吧...!本人經過不斷的研究、測試,完整實現Linux下啟動兩臺MySQL,而且對mysql有了更深入的了解...廢話不多說,走著!
步驟如下:
一、編譯安裝兩個mysql,步驟如下
下載Mysql ,此處以Mysql-6.0.11-alpha.tar.gz 為例
安裝第一個數據庫(主數據庫)
(紅色部分為默認數據庫文件路徑,可改成其他如:data、var等)
tar zxvf mysql-6.0.11-alpha.tar.gz
cd mysql-6.0.11-alpha
./configure --prefix=/usr/local/mysql --sysconfdir=/usr/local/mysql/etc --with-tcp-port=3306 --localstatedir=/usr/local/mysql/localstate --with-unix-socket-path=/tmp/mysql3306.sock --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312,binary --enable-thread-safe-client --with-plugins=innobase --with-mysqld-user=mysql --with-charset=utf8 --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
make && make install
安裝第二個數據庫(從數據庫)
tar zxvf mysql-6.0.11-alpha.tar.gz
cd mysql-6.0.11-alpha
./configure --prefix=/usr/local/mysql3307 --sysconfdir=/usr/local/mysql3307/etc --with-tcp-port=3307 --localstatedir=/usr/local/mysql3307/localstate --with-unix-socket-path=/tmp/mysql3307.sock --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312,binary --enable-thread-safe-client --with-plugins=innobase --with-mysqld-user=mysql --with-charset=utf8 --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
make && make install
如需支持所有字符集 修改為:--with-extra-charsets=all 即可
二、分別初始化數據庫腳本(在編譯目錄執行下)
scripts/mysql_install_db --basedir=/usr/local/mysql/ --user=mysql
scripts/mysql_install_db --basedir=/usr/local/mysql3307/ --user=mysql
註:可用--datadir=PATH參數指定數據庫文件路徑,默認為編譯時-- localstatedir
三、修改從庫配置文件
拷貝配置文件:
cp /usr/local/software/mysql-6.0.11-alpha/support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf
cp /usr/local/software/mysql-6.0.11-alpha/support-files/my-medium.cnf /usr/local/mysql3307/etc/my.cnf
四、修改各個數據庫的my.cnf文件
主要內容如下:
添加InnoDB支持:
[client]
#password = your_password
port = 3307 --數據庫端口號
socket = /tmp/mysqls.sock --sock文件路徑
default-character-set=utf8 --客戶端UTF8連接
[mysqld]
port = 3307 --數據庫端口號
socket = /tmp/mysqls.sock --sock文件路徑
default-storage-engine=INNODB
default-character-set=UTF8 --默認字符集
init_connect=‘SET NAMES utf8‘ --以UTF8連接
skip-name-resolve --取消DNS反向解析
lower_case_table_names=1 --不區分表名大小寫
啟動數據庫(進入各自目錄)
主:./mysqld_safe &
從:./mysqld_safe &
配置開啟自動:
cp /usr/local/software/mysql-6.0.11-alpha/support-files/mysql.server /etc/init.d/mysql
cp /usr/local/software/mysql-6.0.11-alpha/support-files/mysql.server /etc/init.d/mysql3307
修改/etc/init.d/mysql3007中basedir與datadir為即可
basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/var
停止數據庫
主:./mysqladmin shutdown
從:./mysqladmin shutdown
以上各項配置都可以自行修改,以滿足業務需求。
版權所有:Robot_G(swengineer) 歡迎轉載http://blog.csdn.net/swengineer/archive/2011/03/11/6239711.aspx
Linux下安裝啟動多個Mysql