由于公司审计工作的缘故,需要在一台linux数据库服务器上跑两个版本的MYSQL,原来已经在跑的是mysql 4.0编译安装的,安装目录在/usr/local/mysql;欲想知道怎么安装mysql 4.0可以查看我的另一篇BLOG文章:http://523514.blog.51cto.com/513514/1410662
本文主要介绍,在原基础上再部署一个mysql 5.0的版本,安装目录/usr/local/mysql5,端口号:3307;
一、环境
# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.8 (Final)
Release: 5.8
Codename: Final
# getconf LONG_BIT
64
二、下载
cd /usr/local/src/
wget http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.0/mysql-5.0.96.tar.gz
tar xzvf mysql-5.0.96.tar.gz
mkdir -p /usr/local/mysql5
mkdir -p /var/lib/mysql5
三、安装
cd mysql-5.0.96
# cat install.sh
#!/bin/sh
./configure \
--prefix=/usr/local/mysql5 \
--localstatedir=/var/lib/mysql5 --with-comment=Source \
--with-server-suffix=-Community \
--with-mysqld-user=mysql \
--without-debug \
--with-big-tables \
--with-charset=gbk --with-collation=gbk_chinese_ci --with-extra-charsets=all \
--with-pthread \
--enable-static \
--enable-thread-safe-client \
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \
--enable-assembler \
--without-innodb \
--without-ndb-debug
# make
# make install
四、配置
cd /usr/local/mysql5
bin/mysql_install_db --user=mysql
chown -R root:mysql .
chown -R mysql:mysql /var/lib/mysql5
cp share/mysql/my-huge.cnf /etc/my5.cnf
cp share/mysql/mysql.server /etc/init.d/mysql5
chkconfig --add mysql5
编辑 /etc/init.d/mysql5 文件:
找到 my.cnf 全部更改为 my5.cnf
找到 $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
更改为:
$bindir/mysqld_safe --defaults-file=/etc/my5.cnf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
编辑 /etc/my5.cnf 文件:
port = 3306 全部更改为 3307;
socket = /tmp/mysql.sock 全部改为 socket = /tmp/mysql5.sock;
lower_case_table_names = 1 ### 1为忽略大小写 0为不忽略大小写 (可选);
注意事项:
# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22 to server version: 4.0.25
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
----------
默认进入的是mysql 4.0的版本;
如果想进入 mysql 5.0 需要添加参数,如下:
# mysql -p -S /tmp/mysql5.sock
如果不加参数-S,则在默认目录去找 mysql.sock 而不是 mysql5.sock ;