MySQL 5.7 使用systemd 来部署多实例
步骤如下
1.更改my.cnf(直接在mysql 正在使用的配置上增加)
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysqld@3308]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql3308
socket=/var/lib/mysql3308/mysql.sock
#innodb使用O_DIRECT打开数据文件,使用fsync()刷写数据文件跟redo log
#write操作是从MySQL innodb buffer里直接向磁盘上写
innodb_flush_method=O_DIRECT
#avoid ibdata1 too big
innodb_file_per_table=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
user=mysql
port=3308
log-error=/var/log/mysqld3308.log
pid-file=/var/run/mysqld3308/mysqld.pid
character-set-server=utf8
collation-server=utf8_general_ci
explicit_defaults_for_timestamp=1
2.执行命令 systemctl start [email protected]
3.开机启用 systemctl enable [email protected]
4.访问新实例 mysql -uroot -p -S /var/lib/mysql3308/mysql.sock (root用户密码会在第一次启动成功之后写入log-error文件)
完成
遇到的坑
1.权限问题
主要是ibdata1文件
更改文件权限即可(两种方式:更改所属用户组chown -R mysql:mysql xxx,更改用户权限chmod 777 xxx)
2.swap 空间不足或没有
关键异常信息如下
[ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
[ERROR] InnoDB: Cannot allocate memory for the buffer pool
3.SELinux导致的权限问题
setenforce 0 #关闭SELinux(SELinux比较复杂,后续慢慢研究,先关掉再说)
所有失败原因均可查看相关日志文件 (实例中指定的 log-error文件)
参考文档
https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html#systemd-multiple-mysql-instances