一个Mysql(5.5版本)设置多个端口运行多个实例。搞了一天,终于弄好,先备忘一下!
一、设置mysqld_multi
复制一份my.cnf,重命名为my_multi.cnf
修改my_multi.cnf,主要配置项目如下
[mysqld_multi]mysqld = /usr/bin/mysqld_safemysqladmin = /usr/bin/mysqladminuser = rootpassword = 123#默认的3306端口[mysqld6]user = mysqlpid-file = /var/run/mysqld/mysqld.pidsocket = /var/run/mysqld/mysqld.sockport = 3306basedir = /usrdatadir = /var/lib/mysqltmpdir = /tmp#加一个3308的端口[mysqld8]user = mysqlpid-file = /var/run/mysqld/mysqld8.pidsocket = /var/run/mysqld/mysqld8.sockport = 3308basedir = /usrdatadir = /var/lib/mysql8tmpdir = /tmp
二、创建3308端口的数据存储目录
mkdir /var/lib/mysql8chown mysql:mysql /var/lib/mysql8
三、修改文件/etc/apparmor.d/usr.sbin.mysqld
修改完成后重启:/etc/init.d/apparmor restart
/usr/sbin/mysqld { #include#include #include #include #include capability dac_override, capability sys_resource, capability setgid, capability setuid, network tcp, /etc/hosts.allow r, /etc/hosts.deny r, /etc/mysql/*.pem r, /etc/mysql/conf.d/ r, /etc/mysql/conf.d/* r, /etc/mysql/*.cnf r, /usr/lib/mysql/plugin/ r, /usr/lib/mysql/plugin/*.so* mr, /usr/sbin/mysqld mr, /usr/share/mysql/** r, /var/log/mysql.log rw, /var/log/mysql.err rw, /var/lib/mysql/ r, /var/lib/mysql/** rwk, /var/log/mysql/ r, /var/log/mysql/* rw, /var/run/mysqld/mysqld.pid rw, /var/run/mysqld/mysqld.sock w, /run/mysqld/mysqld.pid rw, /run/mysqld/mysqld.sock w, #####主要是添加这些读写权限信息,不然下一步骤初始化数据库时会报无权限错误 /var/lib/mysql8/ r, /var/lib/mysql8/** rwk, /var/run/mysqld/mysqld8.pid rw, /var/run/mysqld/mysqld8.sock w, /run/mysqld/mysqld8.pid rw, /run/mysqld/mysqld8.sock w, /sys/devices/system/cpu/ r, # Site-specific additions and overrides. See local/README for details. #include }
四、初始化数据库
mysql_install_db --user=mysql --datadir=/var/lib/mysql8 &
五、重启数据库(默认打开3306端口的数据库)
service mysql restart
六、打开3308端口的数据库
mysqld_multi --defaults-file=/etc/mysql/my_multi.cnf start 8
七、完事,可以查看下了
netstat -ntlp
终于看到可喜的结果如下!
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1402/mysqldtcp 0 0 127.0.0.1:3308 0.0.0.0:* LISTEN 2202/mysqld
启动:mysqld_multi --defaults-file=/etc/mysql/my_multi.cnf start 8
登陆:mysql -S /var/run/mysqld/mysq8.sock -P 3308
关闭:mysqladmin -uroot -S /var/run/mysqld/mysqld8.sock shutdown -p