如何在一台服务器同时运行两 ( 多 ) 个 MySQL 服务。
1、MySQL 5.6
shell > useradd -r -s /sbin/nologin mysql
shell > wget ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.6/mysql-5.6.27.tar.gz
shell > tar zxf mysql-5.6.27.tar.gz
shell > cd mysql-5.6.27
shell > cmake . ; make ; make install
shell > chown -R root:mysql /usr/local/mysql
shell > chown -R mysql /usr/local/mysql/data
shell > cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
shell > cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
shell > /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
shell > service mysqld start
shell > echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile
shell > source /etc/profile
shell > mysql -e 'select version();' # MySQL 5.6 安装成功
+-----------+
| version() |
+-----------+
| 5.6.27 |
+-----------+
2、MySQL 5.5
shell > wget ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.5/mysql-5.5.46.tar.gz
shell > tar zxf mysql-5.5.46.tar.gz
shell > cd mysql-5.5.46
shell > cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5 # 指定安装路径
shell > make ; make install
shell > chown -R root:mysql /usr/local/mysql5
shell > chown -R mysql /usr/local/mysql5/data
shell > cp /usr/local/mysql5/support-files/my-medium.cnf /etc/my5.cnf
shell > cp /usr/local/mysql5/support-files/mysql.server /etc/init.d/mysqld5
shell > /usr/local/mysql5/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5/ --datadir=/usr/local/mysql5/data/
shell > vim /etc/my5.cnf # 修改端口、socket
port = 3307
socket = /tmp/mysql5.sock
shell > /usr/local/mysql5/bin/mysqld_safe --defaults-file=/etc/my5.cnf & # 指定配置文件路径,启动数据库
shell > mysql -uroot -S /tmp/mysql5.sock -e 'select version();' # MySQL 5.5 安装成功
+------------+
| version() |
+------------+
| 5.5.46-log |
+------------+
shell > mysql -uroot -h127.0.0.1 -P3307 -e 'select version();' # 或者通过指定 IP:PORT 的方式
+------------+
| version() |
+------------+
| 5.5.46-log |
+------------+
3、编写启动脚本
shell > vim /etc/init.d/mysqld5 # 给启动参数指定配置文件路径 ( --defaults-file=/etc/my5.cnf )
'start')
# Start daemon
# Safeguard (relative paths, core dumps..)
cd $basedir
echo $echo_n "Starting MySQL"
if test -x $bindir/mysqld_safe
then
# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe --defaults-file=/etc/my5.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
# Make lock for RedHat / SUSE
if test -w "$lockdir"
then
touch "$lock_file_path"
fi
exit $return_value
else
log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
fi
;;
shell > service mysqld5 stop # OK,我们也可以使用脚本管理 MySQL 5.5 啦!
CentOS 7源码编译安装PHP5.6和Nginx1.7.9及MySQL(搭建LNMP环境)