mysqld_multi多实例配置
添加用户和群组
groupadd mysql #添加mysql用户组
useradd -g mysql mysql #创建mysql用户并把它放到mysql组下
chown -R root:mysql /usr/local/mysql #修改mysql文件属性权限
初始化数据目录
#把用到的工具添加到/usr/bin目录
ln -s /usr/local/mysql/bin/mysqld_multi /usr/bin/mysqld_multi ln -s /usr/local/mysql/scripts/mysql_install_db /usr/bin/mysql_install_db
#初始化四个数据目录
mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql1 --user=mysql
mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql2 --user=mysql
mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql3 --user=mysql
mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql4 --user=mysql
#修改属性
chown -R mysql /data/mysql1
chown -R mysql /data/mysql2
chown -R mysql /data/mysql3
chown -R mysql /dtat/mysql4
配置多实例启动脚本
从MySQL的源码中把复制到/etc/init.d/目录下
cp /usr/local/src/mysql-5.1.60/support-files/mysqld_multi.server /etc/init.d/mysqld_multi.server
配置多实例数据库配置文件
用mysqld_multi工具查看该配置文件的模板方法,命令为:mysqld_multi --example > mysqld_multi.cnf
将其考入/etc/下
[mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld_safe mysqladmin = /usr/local/mysql/bin/mysqladmin user = multi_admin password = my_password [mysqld1] socket = /tmp/mysql.sock1 port = 3307 pid-file = /data/mysql1/mysql1.pid1 datadir = /data/mysql1/ #language = /usr/local/mysql/share/mysql/english user = mysql [mysqld2] socket = /tmp/mysql.sock2 port = 3308 pid-file = /data/mysql2/mysql2.pid2 datadir = /data/mysql2/ #language = /usr/local/mysql/share/mysql/swedish user = mysql [mysqld3] socket = /tmp/mysql.sock3 port = 3309 pid-file = /data/mysql3/mysql3.pid3 datadir = /data/mysql3/ #language = /usr/local/mysql/share/mysql/estonia user = mysql [mysqld4] socket = /tmp/mysql.sock4 port = 3310 pid-file = /data/mysql4.pid4 datadir = /data/mysql4/ #language = /usr/local/mysql/share/mysql/japanese user = mysql |
启动多实例数据库
将/usr/local/mysql/bin加到$PATH环境变量里
export PATH=/usr/local/mysql/bin:$PATH
启动
mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf start
mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf report
#启动具体某一个实例可在start、stop后面加上具体数据1,2,3等
查看运行结果
#查看相应端口是否已经被监听
netstat -tunlp
#查看是否有活动进程
ps -aux|grep mysql
登录相应数据库
#进入端口为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%';
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28792027/viewspace-758087/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28792027/viewspace-758087/