数据库一:
MYSQL版本:mysql-5.0.56
PORT:3306
系统目录:/usr/local/mysql3306
数据库二:
MYSQL版本:mysql-5.1.51
PORT:3307
系统目录:/usr/local/mysql3307
一、查看系统中是否已安装Mysql
①查看已安装的开发包:rpm -qa | grep -i mysql
MySQL-server-5.6.17-1.el6.i686
MySQL-client-5.6.17-1.el6.i686
②卸载mysql
[root@localhost local]# rpm -e MySQL-server-5.6.17-1.el6.i686
[root@localhost local]# rpm -e MySQL-client-5.6.17-1.el6.i686
③删除mysql服务
[root@localhost local]# chkconfig --list | grep -i mysql
[root@localhost local]# chkconfig --del mysql
④删除分散mysql文件夹
[root@localhost local]# whereis mysql 或者 find / -name mysql
mysql: /usr/lib/mysql /usr/share/mysql
清空相关mysql的所有目录以及文件
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysql
rm -rf /usr/my.cnf
参照:http://blog.csdn.net/rosten/article/details/25096159
二.安装开发包
安装 ncurses-devel:否则在./configure时回报checking for termcap functions library... configure: error: No curses/termcap library found错误
yum list|grep ncurses
yum -y install ncurses-devel
yum install ncurses-devel
三.安装mysql数据库实例
1.下载编译包:
# su -
# mkdir ~/src
# cd src
# wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz --不好用
# wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz
2.安装前的初始配置工作:
1).创建一个Mysql用户:
groupadd mysq
useradd -g mysql mysql
2).新建mysql下data和log子目录
# mkdir /usr/local/mysql{3306,3307}
# mkdir /usr/local/mysql{3306,3307}/data
# mkdir /usr/local/mysql{3306,3307}/log
3).修改目录的所属者以及所属组权限
chmod +w /usr/local/mysql{3306,3307} ================之前安装时没有加总提示权限不够不知道是不是这个的原因
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/data/
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/log/
# chmod 750 /usr/local/mysql{3306,3307}/data ========== 安装时没有执行
# chmod 750 /usr/local/mysql{3306,3307}/log ========= 安装时没有执行
4).创建mysql相关目录并配置权限
# mkdir -p /usr/local/mysql{3306,3307}/etc
# chown -R mysql.mysql /usr/local/mysql{3306,3307}/etc
# mkdir -p /var/run/mysqld{3306,3307}
# chmod +w /var/run/mysql{3306,3307}
# chown -R mysql.mysql /var/run/mysqld{3306,3307}
# mkdir -p /var/lib/mysqld{3306,3307}
# chmod +w /var/lib/mysql{3306,3307}
# chown -R mysql.mysql /var/lib/mysqld{3306,3307}
3.解包编译安装 ===这里临时先安装一个
编译数据库一:
# cd ~/src
# tar -zxvf mysql-5.0.56.tar.gz
# cd mysql-5.0.56
./configure --prefix=/usr/local/mysql3306 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3306/etc --localstatedir=/usr/local/mysql3306/data --with-tcp-port=3306 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3306.sock
解压成功。
# make && make install
安装成功后
进入/usr/local/mysql3306这个目录,
看一下是不是已经安装好了呢??
[root@localhost ~]# cd /usr/local/mysql3306/
[root@localhost ~]# ls
bin include info lib libexec man mysql-test share sql-bench
我们把/usr/local/mysql3306/share/mysql这个目录下的my-medium.cnf,复制为my.cnf到/etc目录下。
编译安装完后将配置文件拷贝到想要配置的目录:
cp /usr/local/mysql3306/share/mysql/my-medium.cnf /usr/local/mysql3306/etc/my.cnf
一般情况下my-medium.cnf 中的配置足够使用。应为在./configure时进行了配置所以在share生成的配置文件中已经做了简单地配置
4.编写mysql配置项:
# vim /usr/local/mysql3306/etc/my.cnf
[mysqld]
datadir=/usr/local/mysql3306/data
socket=/tmp/mysql3306.sock
user=mysql
port=3306
pid-file=/var/lib/mysqld3306/mysql.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections= 16384
skip-name-resolve
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 3072
thread_cache_size = 256
sort_buffer_size = 16M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
net_buffer_length = 256M
thread_stack = 8M
query_cache_size = 128M
query_cache_limit = 2M
wait_timeout=7200
interactive_timeout=7200
#log
log-error=/usr/local/mysql3306/log/error.log
log=/usr/local/mysql3306/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql3306/log/slowquery.log
log-bin= /usr/local/mysql3306/log/bin.log
expire_logs_days = 15
sync_binlog = 1
max_binlog_cache_size = 4294967295
local-infile=0
[mysqld_safe]
log-error=/var/log/mysqld3306.log
pid-file=/var/run/mysqld3306/mysqld.pid
5.将mysql的库文件路径加入系统的库文件搜索路径中
方法一:直接做软链接
复制代码 代码如下:
# ln -s /usr/local/mysql3306/lib/mysql /usr/lib/mysql
方法二:利用ldconfig导入系统库
复制代码 代码如下:
# echo "/usr/local/mysql3306/lib" >> /etc/ld.so.conf.d/mysql.conf
# ldconfig
6.输出mysql的头文件到系统头文件
复制代码 代码如下:
# ln -s /usr/local/mysql3306/include/mysql /usr/include/mysql
注: 此处只需将一个mysql实例的库文件添加到系统库,无需多次添加
7.进入相应实例的安装路径,初始化各自配置脚本
做了这些工作以后,还得创造CentOS mysql授权表, 否则数据库也是启动不了。mysql_install_db,这个命令的用途就是做这个的。
数据库一配置:
# cd /usr/local/mysql3306
# bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql3306/data =====
CentOS mysql安装的命令都安装到了/usr/local/mysql3306/bin这个目录中。找一下mysql_install_db 存放在什么位置,这个地方直接在bin文件夹里面执行mysql_install_db会提示命令不可用返回到上一级就好使了。。
安装成功后:
8.复制mysql启动脚本到系统服务目录,并更改脚本配置
CentOS mysql服务器启动,应该是/usr/local/mysql3306/share/mysql目录中的 mysql.server
把mysql.server拷贝到mysqld3306中
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3306
①数据库一配置:
vim /etc/init.d/mysqld3006
搜索如下行,红色标注的为添加的参数
basedir=/usr/local/mysql3306
datadir=/usr/local/mysql3306/data
conf=/usr/local/mysql3306/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
9.系统启动项相关配置
数据库一配置:
# chkconfig --add mysqld3306 #添加开机启动服务
# chkconfig --level 35 mysqld3306 on #设置mysql启动
10.启动mysql
数据库一启动:
# service mysqld3306 start
Starting MySQL SUCCESS! OK成功!
11 添加mysql命令集到系统全局变量
注:如果系统之前未安装mysql客户端,可以将编译好的mysql命令集导入系统全局变量
以后就可以直接使用mysql命令集,而不需要使用绝对路径访问.
复制代码 代码如下:
# echo "PATH=$PATH:/usr/local/mysql3306/bin;export PATH" >> /etc/profile
# source /etc/profile
12. 设置初始账户,并登陆后台:
数据库一:
# /usr/local/mysql3306/bin/mysqladmin -u root password 123456 #设置超级管理员密码
# /usr/local/mysql3306/bin/mysql -P3306 -S/tmp/mysql3306.sock -uroot -p123456 #连接数据库
连接成功!
接着配置另外一台 mysql-5.1.51.tar.gz
编译数据库二:
# cd ~/src
# tar -zxvf mysql-5.1.71.tar.gz
# cd mysql-5.1.71
./configure --prefix=/usr/local/mysql3307 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3307/etc --localstatedir=/usr/local/mysql 3307/data --with-tcp-port=3307 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk -with-ext ra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3307.sock
# make && make install
数据库二配置:
vim /usr/local/mysql3307/etc/my.cnf
7.进入相应实例的安装路径,初始化各自配置脚本
# cd /usr/local/mysql3307
# bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql3307/data
8.复制mysql启动脚本到系统服务目录,并更改脚本配置
CentOS mysql服务器启动,应该是/usr/local/mysql3307/share/mysql目录中的 mysql.server
把mysql.server拷贝到mysqld3307中
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3307
①数据库一配置:
vim /etc/init.d/mysqld3007
搜索如下行,红色标注的为添加的参数
basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/data
conf=/usr/local/mysql3307etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
9.系统启动项相关配置
数据库一配置:
# chkconfig --add mysqld3307 #添加开机启动服务
# chkconfig --level 35 mysqld3307 on #设置mysql启动
10.启动mysql
数据库一启动:
数据库二:
# /usr/local/mysql3307/bin/mysqladmin -u root password 123456 #设置超级管理员密码
# /usr/local/mysql3307/bin/mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456 #连接数据库
注: 因为加了mysql环境变量,以后系统后台可以直接使用mysql命令登录,这里使用绝对路径是为了规范操作
# mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456
# service mysqld3307 start
Starting MySQL SUCCESS! OK成功!
以上参考:http://www.jb51.net/article/48592.htm 对这个链接里的部分内容作了下调整,可以在我本地上正常启动。