江南才子 发表于 2021-7-3 21:43:16

Centos7.1 for MySQL5.6.30源码安装及多实例配置

预备工作:
    OS:Centos7.1

    DATABASE: mysql-5.6.30.tar.gz
      wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/mysql-5.6.30.tar.gz
1. 创建mysql帐号
    创建用户和用户组
# groupadd mysql   
# useradd -g mysql mysql
# passwd mysql2.验证安装包
解压mysql源码包mysql-5.6.30.tar.gz

# mkdir -p /opt/mysql-5.6/
# tar zxvf mysql-5.6.30.tar.gz -C /opt/mysql-5.6
# cd /opt/mysql-5.6/      验证之前是否安装过mysql,若存在mysql相关包,则rpm -e逐个删除(建议先删devel包,再mysql包,最后强制删除libs包,centos 7默认为中为mariadb.*,依次删除)
# rpm -qa|grep mysql       再验证以下编译必备安装包是否安装:
gcc* gcc-c++* cmake autoconf* automake* zlib* ncurses-devel* libtool* bison

      当缺少相关安装包时,需要通过rpm -ivh ***.rpm或yum install RPM_NAME安装
3.源码编译过程
# 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    #默认字符集
# make
# make install
# ln -s /usr/local/mysql-5.6 /usr/local/mysql

4.创建mysql数据目录及/etc/my.cnf
      数据存放目录,默认为basedir下的data目录(实际场景下,建议mount专用盘作为data):

# cd /usr/local/mysql
# mkdir -p /opt/mysql/data1
# chown -R mysql:mysql /opt/mysql
#chown -R mysql:mysql /usr/local/mysql
# vi /etc/my.cnf

port = 3306
socket =/opt/mysql/data1/mysqld.sock


user = mysql
nice = 0


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


quick
quote-names
max_allowed_packet = 16M
default-character-set = utf8


default-character-set = utf84.初始化mysql
建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错

# ./scripts/mysql_install_db --defaults-file=/etc/my.cnf
# ./bin/mysql_secure_installation5.将mysql服务加入init.d管理
建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错

# cp ./bin/mysql /etc/init.d/mysql
# chkconfig --add mysql
# chkconfig mysql on
# chkconfig --list同时更改环境变量 vi ~/.bash_profile,在PATH变量后添加:/usr/local/mysql/bin
6.启动mysql服务的几种方式
mysqld与mysqld_safe的区别在于mysqld_safe宕机后仍能重启
# service mysql start# mysqld_safe --defaults-file=/etc/my.cnf &# mysqld --defaults-file=/etc/my.cnf &

Mysql多实例安装
    多实例的几个好处:mysql多实例共用同一个mysql程序,但是使用不同的配置文件(可以相同)及端口(必须不同)来启动程序,数据文件存放在不同的文件夹中。这些多实例任务相互独立, 可以有效的利用资源,实现资源的逻辑隔离。
   

    上述1-6歩主要安装了使用3306端口的实例,我们同样可以生成其他端口的实例。这里我们通过以下步骤安装3310端口的MySQL实例。


1.创建使用3310端口的mysql数据目录及/etc/my3310.cnf



# cd /usr/local/mysql
# mkdir -p /opt/mysql/data2
# vi /etc/my3010.cnf

port = 3310
socket =/opt/mysql/data2/mysqld.sock


user = mysql
nice = 0


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


quick
quote-names
max_allowed_packet = 16M
default-character-set = utf8


default-character-set = utf82.初始化使用3310端口的mysql
建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错

# ./scripts/mysql_install_db --defaults-file=/etc/my3310.cnf
# ./bin/mysql_secure_installation--defaults-file=/etc/my3310.cnf3.编辑多实例mysql的配置文件

# vi /etc/mysql_multi.cnf


mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin



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



port = 3310
socket =/opt/mysql/data2/mysqld.sock


user = mysql
nice = 0


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


quick
quote-names
max_allowed_packet= 16M
default-character-set= utf8


default-character-set = utf84.启动mysql多实例
# mysqld_multi --defaults-file=/etc/mysql_multi.cnf start 3306
#mysqld_multi--defaults-file=/etc/mysql_multi.cnf start 3310  




  
页: [1]
查看完整版本: Centos7.1 for MySQL5.6.30源码安装及多实例配置