大网数据广告活动
服务器运维问答

Run multiple instances of MySQL on a single Ubuntu server

· 52CE 我爱测

Is it possible to install multiple MySQL Servers instances on an Ubuntu Server, like I can do on Windows Server? The goal is to have 10 MySQL Server instances in one Ubuntu Server installed, each MySQL Server with its own port nu…

问题原文

原帖链接 · Paulo do Porto · CC BY-SA 3.0

Is it possible to install multiple MySQL Servers instances on an Ubuntu Server, like I can do on Windows Server?

The goal is to have 10 MySQL Server instances in one Ubuntu Server installed, each MySQL Server with its own port number and IP address.

已采纳解答

原帖链接 · William Sandin · CC BY-SA 3.0

That is definitely possible. https://dev.mysql.com/doc/refman/5.7/en/multiple-unix-servers.html is a good reference.

Alternative #1: My suggestion based on MySQL's reference is that you make 10 copies of your my.cnf and add them to your /etc/rc.local. In that case you should preferably make use of a tool such as monit to monitor the status and uptime of the instances. Second alternative is to modify the existing start-up script.

The following script is not tested, but gives you an idea of what needs to be done. It loops over 10 MySQL servers, and copy a separate config, create a separate user and data directory, and increment the port number from 3306 to 3317. Make sure to go over the rc.local to change the IP address to your desired IPs, before running rc.local or restarting your server.

Also make sure to configure sane settings in terms of performance utilization to handle all these servers at once. There may be conflicts with ACLs such as SELinux or AppArmor. If you run into problems with this solution and can't figure it out, please leave a comment.

mv /etc/rc.local /etc/rc.local.bak
printf '%s\n' '#!/bin/bash' > /etc/rc.local
chmod 0755 /etc/rc.local
cd /etc/mysql
port=3306
for i in {1..10}
do
   cp my.cnf my-${port}.cnf
   sed -i 's/socket.*/socket\=\/var\/run\/mysqld\/mysqld-${port}.sock/' my-${port}.cnf
   echo "mysqld_safe --defaults-file=/usr/local/mysql/my-${port}.cnf --bind-address=127.0.0.${i} --port=$port --datadir=/var/lib/mysql-${port} " >> /etc/rc.local
   useradd -d /nonexistent -s /bin/false -c "MySQL server listening on ${port}"
   mkdir -m 0700 /var/lib/mysql-${port}
   mysql_install_db --user=mysql --basedir=/var/lib/mysql-${port} --datadir=/var/lib/mysql-${port}/data
   port=$(expr $port + 1)
done
echo 'exit 0' >> /etc/rc.local
mv my.cnf my.cnf.bak
update-rc.d -f mysql remove

Alternative #2: Use mysqld_multi as described on https://dev.mysql.com/doc/refman/5.7/en/mysqld-multi.html.

Alternative #3: A very easy and clean solution would be to install docker and run 10 separate containers with MySQL, with different port and ip numbers. You can setup those overrides in your Dockerfile.

I hope this helps!

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-11-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。