centos单机编译安装多个mysql共存
其实这篇文章的用处不是很大,只是给大家一个多的思路罢了,好了看教程吧.
系统:centos 5.5
需要的软件包:mysql-5.5.22.tar.gz
1.安装前准备
2.安装配置第1个mysql
tar zxf mysql-5.5.22.tar.gz && cd mysql-5.5.22
这里的编译参数有几项你们可以根据自己的情况设置.我将第1个mysql运行在3306端口,安装目录是/usr/local/mysql,数据库存放位置是/data0/mysql/3306/data,mysql启动文件位置是/data0/mysql/3306/mysqld.sock.
然后执行编译和安装命令
make
make install
然后配置目录权限
chmod +w /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
这里要创建下mysql的数据库存放目录
mkdir -p /data0/mysql/3306/data/
mkdir -p /data0/mysql/3306/binlog/
mkdir -p /data0/mysql/3306/relaylog/
chown -R mysql.mysql /data0/mysql/
然后执行数据初始化
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data0/mysql/3306/data --user=mysql
cp support-files/my-medium.cnf /usr/local/mysql/my.cnf
原来mysql默认的配置文件放在/etc/my.cnf,现在多个版本同时运行,需要每个版本都将配置文件单独放在自己的安装目录内.
cp support-files/mysql.server /etc/init.d/mysql06
原来mysql默认采用mysqld脚本,现在每个mysql需要有自己的启动脚本,并通过修改启动脚本来为每个mysql指定采用的配置文件.
chmod 755 /etc/init.d/mysql06
修改/etc/init.d/mysql06,用来指定采用的配置文件位置.
vi /etc/init.d/mysql06
找到conf=/etc/my.cnf
改成conf=/usr/local/mysql/my.cnf
service mysql06 start
chkconfig mysql06 on
好了,可以看到第1个mysql已经成功启动了,接下来我们来编译安装第2个mysql.
2.编译安装第2个mysql
第2个mysql的编译参数跟第1个只是有点不相同罢了.
先删除编译过的mysql包:
rm -fr mysql-5.5.22 && tar zxf mysql-5.5.22.tar.gz && cd mysql-5.5.22
这里就不再给大家说明了,自己看吧.
chmod +w /usr/local/mysql07
chown -R mysql.mysql /usr/local/mysql07
mkdir -p /data0/mysql/3307/data/
mkdir -p /data0/mysql/3307/binlog/
mkdir -p /data0/mysql/3307/relaylog/
chown -R mysql.mysql /data0/mysql/
/usr/local/mysql07/scripts/mysql_install_db --basedir=/usr/local/mysql07/ --datadir=/data0/mysql/3307/data --user=mysql
cp support-files/my-medium.cnf /usr/local/mysql07/my.cnf
cp support-files/mysql.server /etc/init.d/mysql07
chmod 755 /etc/init.d/mysql07
vi /etc/init.d/mysql07
找到conf=/etc/my.cnf
改成conf=/usr/local/mysql07/my.cnf
这里还要对my.cnf文件进行修改:
vi /usr/local/mysql07/my.cnf
然后启动mysql07
service mysql07 start
chkconfig mysql07 on
好了,大家可以看到两个mysql都已经运行起来了.
系统:centos 5.5
需要的软件包:mysql-5.5.22.tar.gz
1.安装前准备
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel \ freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel \ glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel cmake \ ncurses ncurses-devel curl curl-devel vim ntsysv make libtool
wget http://download.slogra.com/mysql/mysql-5.5.22.tar.gz useradd -M -r -s /sbin/nologin mysql
2.安装配置第1个mysql
tar zxf mysql-5.5.22.tar.gz && cd mysql-5.5.22
cmake . \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \ -DMYSQL_DATADIR=/data0/mysql/3306/data \ -DMYSQL_UNIX_ADDR=/data0/mysql/3306/mysqld.sock \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=0 \ -DWITH_ARCHIVE_STORAGE_ENGINE=0 \ -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_TCP_PORT=3306 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_DEBUG=0 \ -DWITH_EMBEDDED_SERVER=1 \ -DWITH_SSL=system \ -DWITH_READLINE=1
这里的编译参数有几项你们可以根据自己的情况设置.我将第1个mysql运行在3306端口,安装目录是/usr/local/mysql,数据库存放位置是/data0/mysql/3306/data,mysql启动文件位置是/data0/mysql/3306/mysqld.sock.
然后执行编译和安装命令
make
make install
然后配置目录权限
chmod +w /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
这里要创建下mysql的数据库存放目录
mkdir -p /data0/mysql/3306/data/
mkdir -p /data0/mysql/3306/binlog/
mkdir -p /data0/mysql/3306/relaylog/
chown -R mysql.mysql /data0/mysql/
然后执行数据初始化
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data0/mysql/3306/data --user=mysql
cp support-files/my-medium.cnf /usr/local/mysql/my.cnf
原来mysql默认的配置文件放在/etc/my.cnf,现在多个版本同时运行,需要每个版本都将配置文件单独放在自己的安装目录内.
cp support-files/mysql.server /etc/init.d/mysql06
原来mysql默认采用mysqld脚本,现在每个mysql需要有自己的启动脚本,并通过修改启动脚本来为每个mysql指定采用的配置文件.
chmod 755 /etc/init.d/mysql06
修改/etc/init.d/mysql06,用来指定采用的配置文件位置.
vi /etc/init.d/mysql06
找到conf=/etc/my.cnf
改成conf=/usr/local/mysql/my.cnf
service mysql06 start
chkconfig mysql06 on
好了,可以看到第1个mysql已经成功启动了,接下来我们来编译安装第2个mysql.
2.编译安装第2个mysql
第2个mysql的编译参数跟第1个只是有点不相同罢了.
先删除编译过的mysql包:
rm -fr mysql-5.5.22 && tar zxf mysql-5.5.22.tar.gz && cd mysql-5.5.22
cmake . \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql07/ \ -DMYSQL_DATADIR=/data0/mysql/3307/data \ -DMYSQL_UNIX_ADDR=/data0/mysql/3307/mysqld.sock \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=0 \ -DWITH_ARCHIVE_STORAGE_ENGINE=0 \ -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_TCP_PORT=3307 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_DEBUG=0 \ -DWITH_EMBEDDED_SERVER=1 \ -DWITH_SSL=system
这里就不再给大家说明了,自己看吧.
chmod +w /usr/local/mysql07
chown -R mysql.mysql /usr/local/mysql07
mkdir -p /data0/mysql/3307/data/
mkdir -p /data0/mysql/3307/binlog/
mkdir -p /data0/mysql/3307/relaylog/
chown -R mysql.mysql /data0/mysql/
/usr/local/mysql07/scripts/mysql_install_db --basedir=/usr/local/mysql07/ --datadir=/data0/mysql/3307/data --user=mysql
cp support-files/my-medium.cnf /usr/local/mysql07/my.cnf
cp support-files/mysql.server /etc/init.d/mysql07
chmod 755 /etc/init.d/mysql07
vi /etc/init.d/mysql07
找到conf=/etc/my.cnf
改成conf=/usr/local/mysql07/my.cnf
这里还要对my.cnf文件进行修改:
vi /usr/local/mysql07/my.cnf
[client] port = 3307 socket = /data0/mysql/3307/mysql.sock [mysqld] port = 3307 socket = /data0/mysql/3307/mysql.sock basedir = /usr/local/mysql07 datadir = /data0/mysql/3307/data log-error = /data0/mysql/3307/mysql_error.log pid-file = /data0/mysql/3307/mysql.pid log-bin = /data0/mysql/3307/binlog/binlog relay-log-index = /data0/mysql/3307/relaylog/relaylog relay-log-info-file = /data0/mysql/3307/relaylog/relaylog relay-log = /data0/mysql/3307/relaylog/relaylog
然后启动mysql07
service mysql07 start
chkconfig mysql07 on
好了,大家可以看到两个mysql都已经运行起来了.
评论: