有时根据业务需要,会要求实现在一台服务器安装两个mysql。
系统:rhel 5.0(64位) 原装mysql.5.04 端口 3306
要求:在原有基础上再装一个mysql-5.0.77
1:开始:下载源码 mysql-5.0.77.tar.gz
http://downloads.mysql.com/archives.php?p=mysql-5.0
2:服务器上直接下载:
wget -b http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.77.tar.gz
3:cp到/usr/local目录下 并且
4:解压:tar -zxvf mysql-5.0.77.tar.gz 进入解压目录编译安装:
5:配置成功后会提示:
MySQL has a Web site at http://www.mysql.com/ which carries details on the
latest release, upcoming features, and other information to make your
work or play with MySQL more productive. There you can also find
information about mailing lists for MySQL discussion.
Remember to check the platform specific part of the reference manual for
hints about installing MySQL on your platform. Also have a look at the
files in the Docs directory.
Thank you for choosing MySQL!
6:编译安装
#make&&make install
7: 安装后的配置
将mysql的配置文件copy到/usr/local/mysql 目录下,并更名为my.cnf
修改my.cnf 加入:
[mysqld]
basedir = /usr/local/mysql 定义mysql程序目录
datadir = /usr/local/mysql/data 定义数据目录
并把3306端口改为其他端口防止跟以前的mysql端口冲突!
------------------------------------------------------
根据机器配置的不同选择不同的文件:
/usr/local/mysql/share/mysql/my-small.cnf 最小配置安装,内存<=64M,数据数量最少
/usr/local/mysql/share/mysql/my-large.cnf 内存=512M
/usr/local/mysql/share/mysql/my-medium.cnf 32M<内存<64M,或者内存有128M,但是数据库与web服务器公用内存
/usr/local/mysql/share/mysql/my-huge.cnf 1G<内存<2G,服务器主要运行mysql
/usr/local/mysql/share/mysql/my-innodb-heavy-4G.cnf 最大配置安装,内存至少4G
------------------------------------------------------
# groupadd mysql //添加MySQL组
# useradd -g mysql mysql//添加 mysql 用户
注:以上两步可以不操作因为原有系统已有mysql用户和用户组,如果创建会提示exists
# cd /usr/local/mysql //进入MySQL的安装目录
初始化数据库
# bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
# chown -R root:mysql . //设置权限,注意后面有一个 "."
# chown -R mysql /usr/local/mysql //设置 mysql 目录权限
# bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf & //启动mysql
# bin/mysqladmin -u root password password //修改root用户的密码,这里的root用户指的是mysql的root用户,与linux的root用户无关。红色的password就是你需要设置的新密码,牢记!
# bin/mysql -u root -p //如果正常的话,用这个名字可以登录,在输入密码后,出现mysql > 的提示符表明登录成功。用quit命令可退出
以下命令用于设置mysql开机自动运行
# cd mysql-5.0.77 //再次进入解压后的目录,即源码目录。
# cp support-files/mysql.server /etc/init.d/mysqld2 //将mysql.server这个文件copy到/etc/init.d/目录下,并更名为mysqld2
# chmod 755 /etc/init.d/mysqld2 //给/etc/init.d/mysql这个文件赋予“执行”权限
# chkconfig --add mysqld2 //加入到开机自动运行
对启动文件mysqld2做出的必要修改
修改下面的内容:
1.datadir=/usr/local/mysql/data
2.conf=/usr/local/mysql/my.cnf
3.把$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &替换为
"$bindir/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &"(双引号中的)
# service mysqld2 restart //重新启动MySQL