mysql多实例安装
1.配置/etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe --此处要求mysqld_safe 如果是mysqld 则用mysqld_multi 无法启动
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = root --增加数据库root pass是root的密码 如果不设置,mysqld_multi 无法stop
pass =root
#log = /usr/local/mysql/data/mysql_multi.log
[mysqld3306]
port=3306
basedir=/usr/local/mysql
datadir=/mysql/data
socket=/tmp/mysql3306.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-symbolic-links
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#default_authentication_plugin=mysql_native_password
server_id=101
character-set-server=utf8
log-bin=mysql-bin
binlog_format=mixed
#log-fomat=row
[mysqld3307]
port=3307
basedir=/usr/local/mysql
datadir=/mysql/3307/data
socket=/tmp/mysql3307.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-symbolic-links
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#default_authentication_plugin=mysql_native_password
server_id=102
character-set-server=utf8
[mysqld3308]
port=3308
basedir=/usr/local/mysql
datadir=/mysql/3308/data
socket=/tmp/mysql3308.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-symbolic-links
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#default_authentication_plugin=mysql_native_password
server_id=103
character-set-server=utf8
[mysqld3309]
port=3309
basedir=/usr/local/mysql
datadir=/mysql/3309/data
socket=/tmp/mysql3309.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-symbolic-links
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#default_authentication_plugin=mysql_native_password
server_id=104
character-set-server=utf8
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
2.mkdir -p /mysql/{3306,3307,3308,3309}/data
chown -R mysql.mysql /mysql
初始化数据库
依次执行:
/usr/local/mysql/bin/mysqld --initialize-insecure --datadir=/mysql/3306/data --basedir=/usr/local/mysql --user=mysql /*--initialize 会生成随机密码 --initialize-insecure 不生成随机密码*/
3.将/usr/local/mysql/support-files/mysqld_multi.server 拷贝到/etc/init.d/mysqld_multi
4.执行/etc/init.d/mysqld_multi start
如果报错
WARNING: my_print_defaults command not found.
Please make sure you have this command available and
in your path. The command is available from the latest
MySQL distribution.
ABORT: Can't find command 'my_print_defaults'.
This command is available from the latest MySQL
distribution. Please make sure you have the command
in your PATH.
执行export PATH=/usr/local/mysql/bin:$PATH
把PATH 加到环境变量里
查看可以直接使用 mysqld_multi report
5.启动单独的实例 mysqld_multi start 3306 注意这里的gnr 是mysqld后面的数字 不是全部的mysqld3306,否则提示无效
6.如果各个实例的用户密码不一样,在/etc/my.cnf各个实例模块里添加对应的user 和pass