mysql多实例的好处就不多说了 这里直接进入主题
- mkfs.ext4 -L DB /dev/sdb
- mkdir /disk2
- mount /dev/sdb /disk2
- /dev/sdb /disk2 ext4 defaults 0 0
- tar xf mysql-5.1.60.tar.gz
- cd mysql-5.1.60
- ./configure --prefix=/disk2/mysql5.1/ --with-charset=gb2312 --with-extra-charsets=utf8,gb2312 --with-extra-charsets=gbk,gb2312
- make
- make install
- ./configure --prefix=/disk2/mysql5.2/ --with-charset=gb2312 --with-extra-charsets=utf8,gb2312 --with-extra-charsets=gbk,gb2312
- make
- make install
- tar xf /mysql-5.5.25a.tar.gz
- tar xf cmake-2.8.6.tar.gz
- tar xf cmake-2.8.6.tar.gz
- cd cmake-2.8.6
- ./configure
- make
- make install
- cd ..
- tar xf mysql-5.5.25a.tar.gz
- cd mysql-5.5.25a
- cmake -DCMAKE_INSTALL_PREFIX=/disk2/mysql5.5 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=OFF -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
- make
- make install
- cd /usr/local/webserver/mysql
- cd /disk2/mysql5.1/bin
- ./mysql_install_db --datadir=/disk2/mysql5.1/data/3316 --user=mysql
- ./mysql_install_db --datadir=/disk2/mysql5.1/data/3317 --user=mysql
- ./mysql_install_db --datadir=/disk2/mysql5.1/data/3318 --user=mysql
- cd /disk2/mysql5.5/scripts
- ./mysql_install_db --datadir=/disk2/mysql5.5/data/3356 --user=mysql
- ./mysql_install_db --datadir=/disk2/mysql5.5/data/3356 --user=mysql
- ./mysql_install_db --datadir=/disk2/mysql5.5/data/3356 --user=mysql
- chown -R mysql:mysql /disk2/mysql5.1/data/*
- chown -R mysql:mysql /disk2/mysql5.2/data/*
- chown -R mysql:mysql /disk2/mysql5.5/data/*
- cp /root/mysql-5.1.60/support-files/mysqld_multi.server /etc/init.d/mysql_multi5.1.server
- cp /root/mysql-5.2/support-files/mysqld_multi.server /etc/init.d/mysql_multi5.2.server
- cp /root/mysql-5.5.25a/support-files/mysqld_multi.server /etc/init.d/mysql_multi5.5.server
- sed -i -e "s#basedir=/usr/local/mysql#basedir=/disk2/mysql5.1#" -e "s#bindir=/usr/local/mysql/bin#bindir=/disk2/mysql5.1/bin#"/etc/init.d/mysql_multi5.1.server
- sed -i -e "s#basedir=/usr/local/mysql#basedir=/disk2/mysql5.2#" -e "s#bindir=/usr/local/mysql/bin#bindir=/disk2/mysql5.2/bin#"/etc/init.d/mysql_multi5.2.server
- sed -i -e "s#basedir=/usr/local/mysql#basedir=/disk2/mysql5.5#" -e "s#bindir=/usr/local/mysql/bin#bindir=/disk2/mysql5.5/bin#"/etc/init.d/mysql_multi5.5.server
配置文件内容如下
- cd /disk2/msyql5.1
- ./bin/mysqld_multi --example >> ./mysqld_multi.cnf
- vim mysqld_multi.cnf
- [mysqld_multi]
- mysqld = /disk2/mysql5.1/bin/mysqld_safe
- mysqladmin = /disk2/mysql5.1/bin/mysqladmin
- #user = multi_admin
- #password = my_password
- [mysqld1]
- socket = /tmp/mysql.sock1
- port = 3316
- pid-file = /disk2/mysql5.1/data/3316/hostname.pid3316
- datadir = /disk2/mysql5.1/data/3316
- language = /disk2/mysql5.1/share/mysql/english
- user = mysql
- [mysqld2]
- socket = /tmp/mysql.sock2
- port = 3317
- pid-file = /disk2/mysql5.1/data/3317/hostname.pid3317
- datadir = /disk2/mysql5.1/data/3317
- language = /disk2/mysql5.1/share/mysql/english
- user = mysql
- [mysqld3]
- socket = /tmp/mysql.sock3
- port = 3318
- pid-file = /disk2/mysql5.1/data/3318/hostname.pid3318
- datadir = /disk2/mysql5.1/data/3318
- language = /disk2/mysql5.1/share/mysql/english
- user = mysql
- cd /disk2/msyql5.2
- ./bin/mysqld_multi --example >> ./mysqld_multi.cnf
- vim mysqld_multi.cnf
- [mysqld_multi]
- mysqld = /disk2/mysql5.2/bin/mysqld_safe
- mysqladmin = /disk2/mysql5.2/bin/mysqladmin
- #user = multi_admin
- #password = my_password
- [mysqld1]
- socket = /tmp/mysql.sock21
- port = 3326
- pid-file = /disk2/mysql5.2/data/3326/hostname.pid3326
- datadir = /disk2/mysql5.2/data/3326
- language = /disk2/mysql5.2/share/mysql/english/
- user = mysql
- [mysqld2]
- socket = /tmp/mysql.sock22
- port = 3327
- pid-file = /disk2/mysql5.2/data/3327/hostname.pid3327
- datadir = /disk2/mysql5.2/data/3327
- language = /disk2/mysql5.2/share/mysql/english/
- user = mysql
- [mysqld3]
- socket = /tmp/mysql.sock23
- port = 3328
- pid-file = /disk2/mysql5.2/data/3328/hostname.pid3328
- datadir = /disk2/mysql5.2/data/3328
- language = /disk2/mysql5.2/share/mysql/english/
- user = mysql
- cd /disk2/msyql5.5
- ./bin/mysqld_multi --example >> ./mysqld_multi.cnf
- vim mysqld_multi.cnf
- [mysqld_multi]
- mysqld = /disk2/mysql5.5/bin/mysqld_safe
- mysqladmin = /disk2/mysql5.5/bin/mysqladmin
- #user = multi_admin
- #password = my_password
- [mysqld4]
- socket = /tmp/mysql.sock51
- port = 3356
- pid-file = /disk2/mysql5.5/data/3356/hostname.pid3356
- datadir = /disk2/mysql5.5/data/3356
- language = /disk2/mysql5.5/share/english
- user = mysql
- [mysqld5]
- socket = /tmp/mysql.sock52
- port = 3357
- pid-file = /disk2/mysql5.5/data/3357/hostname.pid3357
- datadir = /disk2/mysql5.5/data/3357
- language = /disk2/mysql5.5/share/english
- user = mysql
- [mysqld6]
- socket = /tmp/mysql.sock53
- port = 3358
- pid-file = /disk2/mysql5.5/data/3358/hostname.pid3358
- datadir = /disk2/mysql5.5/data/3358
- language = /disk2/mysql5.5/share/english
- user = mysql
- ./bin/mysql_multi --defaults-extra-file=/disk2/mysql5.1/mysqld_multi.cnf report
- ./bin/mysql_multi --defaults-extra-file=/disk2/mysql5.1/mysqld_multi.cnf start
- cd /disk2/mysql5.2
- ./bin/mysql_multi --config-file==/disk2/mysql5.2/mysqld_multi.cnf start
- cd /disk2/mysql5.5
- ./bin/mysql_multi --defaults-extra-file=/disk2/mysql5.5/mysqld_multi.cnf start
- [root@server54 bin]# netstat -tnlp|grep mysqld
- tcp 0 0 0.0.0.0:3316 0.0.0.0:* LISTEN 13777/mysqld
- tcp 0 0 0.0.0.0:3317 0.0.0.0:* LISTEN 13790/mysqld
- tcp 0 0 0.0.0.0:3318 0.0.0.0:* LISTEN 13797/mysqld
- tcp 0 0 0.0.0.0:3356 0.0.0.0:* LISTEN 16836/mysqld
- tcp 0 0 0.0.0.0:3357 0.0.0.0:* LISTEN 16843/mysqld
- tcp 0 0 0.0.0.0:3326 0.0.0.0:* LISTEN 25719/mysqld
- tcp 0 0 0.0.0.0:3358 0.0.0.0:* LISTEN 16849/mysqld
- tcp 0 0 0.0.0.0:3327 0.0.0.0:* LISTEN 25728/mysqld
- tcp 0 0 0.0.0.0:3328 0.0.0.0:* LISTEN 25732/mysqld
我再额外说明一点:
因为mysql启动的时候会首先检查/etc目录下是否有my.cnf配置文件,如果你以前用rpm包安装过mysqld会默认生成在/etc/mysql/my.cnf中,如果你想使用多实例,建议重命名这个文件,因为很多无法启动的错误和一些诡异的mysql服务错误是因为这个配置文件导致的