本文講利用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%';
一、上傳RPM包到服務器上 二、安裝mysql服務器端rpm -ivhMySQL-server-5.5.8-1.rhel5.x86_64.rpm 三、安裝mysql客戶端 rpm -ivhMySQL-client-5.5.8-1.rhel5.x86_64.rpm 四、創建目錄 在/data下創建目錄,把原來的數據目錄/var/lib/mysql 移到/data/mysql/data1和/data/mysql/data2下,並修改mysql目錄以及子目錄權限 PS:安裝後默認的幾個重要目錄 目錄 內容/var/lib/mysql 數據文件,日志文件等等/usr/bin客戶端程序和腳本/usr/share/mysql 錯誤消息和字符集文件/etc/rc.d/init.d/mysql 啟動腳本文件 創建目錄 修改權限 五、修改並上傳配置文件my.cnf 從服務器上的/usr/share/mysql目錄中把my-innodb-heavy-4G.cnf拷貝一份到本地。編輯其內容增加數據文件和日志文件的目錄,修改socket目錄。 六、用mysql_multi啟動多個服務 啟動:mysqld_multi --defaults-file=/etc/my.cnf start1,2 &查看是否啟動:mysqld_multi --defaults-file=/etc/my.cnfreport 1 七、查看端口是否打開 八、連接進入指定的mysql服務器 mysql -u root -S/tmp/mysql1.sock 或者mysql -uroot -P3307 -h127.0.0.1 九、記得關閉防火牆
你用root去啟動了吧,加個參數把,--user=mysql
------------------------------------------------------------------
./mysqld_multi --user=mysql --defaults-extra-file=/etc/mysqld_multi.cnf start 2