Centos7.1 for MySQL5.6.30源码安装及多实例配置
时间:2016-07-23 16:01 来源:linux.it.net.cn 作者:IT
预备工作:
OS:Centos7.1
DATABASE: mysql-5.6.30.tar.gz
1. 创建mysql帐号
创建用户和用户组
1
2
3
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
[root@localhost ~]# passwd mysql
2.验证安装包
解压mysql源码包mysql-5.6.30.tar.gz
1
2
3
[root@localhost ~]# mkdir -p /opt/mysql-5.6/
[root@localhost ~]# tar zxvf mysql-5.6.30.tar.gz -C /opt/mysql-5.6
[root@localhost ~]# cd /opt/mysql-5.6/
验证之前是否安装过mysql,若存在mysql相关包,则rpm -e逐个删除(建议先删devel包,再mysql包,最后强制删除libs包)
1
[root@localhost mysql-5.6]# rpm -qa|grep mysql
再验证以下编译必备安装包是否安装:
gcc*,gcc-c++*,cmake,autoconf*,automake*,zlib*,ncurses-devel*,libtool*,bison
当缺少相关安装包时,需要通过rpm -ivh ***.rpm或yum install RPM_NAME安装
3.源码编译过程
1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost mysql-5.6]# cmake .
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6 #安装目录
-DWITH_INNOBASE_STORAGE_ENGINE=1 #支持InnoDB引擎
-DWITH-READLINE=1 #支持快捷键
-DEXTRA_CHARSETS=all #安装所有字符集
-DENABLED_LOCAL_INFILE=1 #从本地导入数据
-DWITH_EMBEDDED_SERVER=1 #编译Embedded Mysql库
-DWITH_SSL=bundled #
-DDEFAULT_CHARSET=utf8 #默认字符集
[root@localhost mysql-5.6]# make
[root@localhost mysql-5.6]# make install
[root@localhost mysql-5.6]# ln -s /usr/local/mysql-5.6 /usr/local/mysql
4.创建mysql数据目录及/etc/my.cnf
数据存放目录,默认为basedir下的data目录(实际场景下,建议mount专用盘作为data):
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
30
31
32
[root@localhost mysql-5.6]# cd /usr/local/mysql
[root@localhost mysql]# mkdir -p /opt/mysql/data1
[root@localhost mysql]# chown -R mysql.mysql /opt/mysql
[root@localhost mysql]# vi /etc/my.cnf
[client]
port = 3306
socket =/opt/mysql/data1/mysqld.sock
[mysqld_safe]
user = mysql
nice = 0
[mysqld]
port = 3306
pid-file = /opt/mysql/data1/mysqld.pid
socket = /opt/mysql/data1/mysqld.sock
basedir = /usr/local/mysql
datadir = /opt/mysql/data1/
tmpdir = /opt/mysql/data1/
log-error = /opt/mysql/data1/mysqld.log
slow_query_log =1
slow_query_log_file = /opt/mysql/data1/mysql-slow.log
log_bin = /opt/mysql/data1/mysql-bin.log
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
default-character-set = utf8
[mysql]
default-character-set = utf8
4.初始化mysql
建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错
1
2
[root@localhost mysql]# ./scripts/mysql_install_db --defaults-file=/etc/my.cnf
[root@localhost mysql]# ./bin/mysql_secure_installation
5.将mysql服务加入init.d管理
建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错
1
2
3
4
[root@localhost mysql]# cp /bin/mysql.service /etc/init.d/mysql
[root@localhost mysql]# chkconfig --add mysql
[root@localhost mysql]# chkconfig mysql on
[root@localhost mysql]# chkconfig --list
同时更改环境变量 vi ~/.bash_profile,在PATH变量后添加:/usr/local/mysql/bin
6.启动mysql服务的几种方式
mysqld与mysqld_safe的区别在于mysqld_safe宕机后仍能重启
1
[root@localhost mysql]# service mysql start
1
[root@localhost mysql]# mysqld_safe --defaults-file=/etc/my.cnf &
1
[root@localhost mysql]# mysqld --defaults-file=/etc/my.cnf &
Mysql多实例安装
上述1-6歩主要安装了使用3306端口的实例,我们同样可以生成其他端口的实例。这里我们通过以下步骤安装3310端口的MySQL实例。
1.创建使用3310端口的mysql数据目录及/etc/my3310.cnf
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
30
31
[root@localhost mysql-5.6]# cd /usr/local/mysql
[root@localhost mysql]# mkdir -p /opt/mysql/data2
[root@localhost mysql]# vi /etc/my3010.cnf
[client]
port = 3310
socket =/opt/mysql/data2/mysqld.sock
[mysqld_safe]
user = mysql
nice = 0
[mysqld]
port = 3310
pid-file = /opt/mysql/data2/mysqld.pid
socket = /opt/mysql/data2/mysqld.sock
basedir = /usr/local/mysql
datadir = /opt/mysql/data2/
tmpdir = /opt/mysql/data2/
log-error = /opt/mysql/data2/mysqld.log
slow_query_log =1
slow_query_log_file = /opt/mysql/data2/mysql-slow.log
log_bin = /opt/mysql/data2/mysql-bin.log
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
default-character-set = utf8
[mysql]
default-character-set = utf8
2.初始化使用3310端口的mysql
建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错
1
2
[root@localhost mysql]# ./scripts/mysql_install_db --defaults-file=/etc/my3310.cnf
[root@localhost mysql]# ./bin/mysql_secure_installation --defaults-file=/etc/my3310.cnf
3.编辑多实例mysql的配置文件
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[root@localhost mysql]# vi /etc/mysql_multi.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
[mysqld3306]
port = 3306
pid-file = /opt/mysql/data1/mysqld.pid
socket = /opt/mysql/data1/mysqld.sock
basedir = /usr/local/mysql
datadir = /opt/mysql/data1/
tmpdir = /opt/mysql/data1/
log-error = /opt/mysql/data1/mysqld.log
slow_query_log =1
slow_query_log_file = /opt/mysql/data1/mysql-slow.log
log_bin = /opt/mysql/data1/mysql-bin.log
[mysqld3310]
[client]
port = 3310
socket =/opt/mysql/data2/mysqld.sock
[mysqld_safe]
user = mysql
nice = 0
[mysqld]
port = 3310
pid-file = /opt/mysql/data2/mysqld.pid
socket = /opt/mysql/data2/mysqld.sock
basedir = /usr/local/mysql
datadir = /opt/mysql/data2/
tmpdir = /opt/mysql/data2/
log-error = /opt/mysql/data2/mysqld.log
slow_query_log =1
slow_query_log_file = /opt/mysql/data2/mysql-slow.log
log_bin = /opt/mysql/data2/mysql-bin.log
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
default-character-set = utf8
[mysql]
default-character-set = utf8
4.启动mysql多实例
1
2
[root@localhost mysql]# mysqld_multi --defaults-file=/etc/mysql_multi.cnf start 3306
[root@localhost mysql]# mysqld_multi --defaults-file=/etc/mysql_multi.cnf start 3310
1
<br>
(责任编辑:IT)
预备工作: OS:Centos7.1 DATABASE: mysql-5.6.30.tar.gz 1. 创建mysql帐号 创建用户和用户组
2.验证安装包 解压mysql源码包mysql-5.6.30.tar.gz
验证之前是否安装过mysql,若存在mysql相关包,则rpm -e逐个删除(建议先删devel包,再mysql包,最后强制删除libs包)
再验证以下编译必备安装包是否安装: gcc*,gcc-c++*,cmake,autoconf*,automake*,zlib*,ncurses-devel*,libtool*,bison
当缺少相关安装包时,需要通过rpm -ivh ***.rpm或yum install RPM_NAME安装 3.源码编译过程
4.创建mysql数据目录及/etc/my.cnf 数据存放目录,默认为basedir下的data目录(实际场景下,建议mount专用盘作为data):
4.初始化mysql 建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错
5.将mysql服务加入init.d管理 建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错
同时更改环境变量 vi ~/.bash_profile,在PATH变量后添加:/usr/local/mysql/bin 6.启动mysql服务的几种方式 mysqld与mysqld_safe的区别在于mysqld_safe宕机后仍能重启
Mysql多实例安装 上述1-6歩主要安装了使用3306端口的实例,我们同样可以生成其他端口的实例。这里我们通过以下步骤安装3310端口的MySQL实例。
1.创建使用3310端口的mysql数据目录及/etc/my3310.cnf
2.初始化使用3310端口的mysql 建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错
3.编辑多实例mysql的配置文件
4.启动mysql多实例
(责任编辑:IT) |