CentOS安装多个Mysql

目录导航

安装的mysql占用端口分别为3306和3307

下载mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz,这个是编译完的二进制包

可阅读文件夹下的INSTALL-BINARY进行安装

两个mysql都安装在opt下面

3306安装命令如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
shell> groupadd mysql

shell> useradd -r -g mysql mysql

shell> cd /opt

shell> tar zxvf mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz

shell> mv mysql-5.6.20-linux-glibc2.5-x86_64 mysql3306

shell> cd mysql3306

shell> mkdir log

shell> mkdir tmp

shell> chown -R mysql .

shell> chgrp -R mysql .

shell> scripts/mysql_install_db --user=mysql

shell> chown -R root .

shell> chown -R mysql data

shell> cp support-files/my-default.cnf my.cnf

shell> cp support-files/mysql.server /etc/init.d/mysqld3306

修改my.cnf,内容如下

1
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
 basedir = /opt/mysql3306 
 datadir = /opt/mysql3306/data 
 port = 3306 
# server_id = 
 socket = /tmp/mysql3306.sock
 pid-file=/opt/mysql3306/tmp/mysql.pid

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

#log
log-error=/opt/mysql3306/log/error.log
general_log=ON
general_log_file=/opt/mysql3306/log/mysql.log
long_query_time=2
#log-show-queries=/opt/mysql3306/log/showquery.log
log-bin=/opt/mysql3306/log/bin.log
expire_logs_days=15
sync_binlog=1
#max_binlog_cache_size = 4294967295
local-infile=0
[mysqld_safe]
log-error=/opt/mysql3306/mysqld3306.log
pid-file=/opt/mysql3306/mysqld.pid

修改/etc/init.d/mysqld3306
主要修改如下

1
basedir=/opt/mysql3306
datadir=/opt/mysql3306/data
conf=/opt/mysql3306/my.cnf

...

$bindir/mysqld_safe --defaults-file=$conf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?

3307安装步骤如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
shell> tar zxvf mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz

shell> mv mysql-5.6.20-linux-glibc2.5-x86_64 mysql3307

shell> cd mysql3307

shell> mkdir log

shell> mkdir tmp

shell> chown -R mysql .

shell> chgrp -R mysql .

shell> scripts/mysql_install_db --basedir=/opt/mysql2012 --datadur=/opt/mysql2012 --user=mysql

shell> chown -R root .

shell> chown -R mysql data

shell> cp support-files/my-default.cnf my.cnf

shell> cp support-files/mysql.server /etc/init.d/mysqld3307

修改my.cnf和/etc/init.d/mysqld3307,修改方式与3306的一样,只是将其中的3306改成3307即可。

最后,启动mysql

1
2
3
shell> service mysqld3306 start
shell> service mysqld3307 start
看见SUCCESS就成功了

开机自启动

1
2
shell> chkconfig --add mysqld3306
shell> chkconfig --add mysqld3307