MySQL源碼編譯安裝 ( 5.5 、5.6 共存 )
簡介:
如何在一台伺服器同時運行兩 ( 多 ) 個 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 啦!
源碼編譯安裝MySQL 5.7.9
CentOS 7源碼編譯安裝PHP5.6和Nginx1.7.9及MySQL(搭建LNMP環境)
MySQL 5.7.9源碼編譯安裝說明
CentOS 6.6 下源碼編譯安裝MySQL 5.7.5
Ubuntu 12.04下原始碼安裝MySQL5.6以及Python-MySQLdb
MySQL-5.5.38通用二進位安裝
CentOS 7下源碼安裝MySQL 5.6
本文永久更新連結地址: