豫ICP备17040950号-2

CentOS安装多版本MySQL

文章目录
  1. 1. 前言
  2. 2. 安装详解
    1. 2.1. 安装开发包
    2. 2.2. 下载MySQL
    3. 2.3. 安装前准备
    4. 2.4. 解压MySQL
    5. 2.5. 编译安装MySQL
    6. 2.6. 配置MySQL
    7. 2.7. 启动MySQL
  3. 3. 远程连接
  4. 4. 书签

前言

卓音工作室的服务器中,已经安装了MySQL5.7。但是,confluence和jira不支持MySQL5.7,为了安装这两款软件,必须安装MySQL5.6或更低的版本。

安装详解

安装开发包

1
yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* --setopt=protected_multilib=false

下载MySQL

搜狐镜像:http://mirrors.sohu.com/mysql/MySQL-5.6/
选择下载:mysql-5.6.34.tar.gz

安装前准备

1、创建一个Mysql用户,useradd mysql

2、新建mysql下data和log子目录

1
2
mkdir -p /usr/local/mysql{3306,3307}/data            
mkdir -p /usr/local/mysql{3306,3307}/log

3、修改目录的所属者以及所属组权限

1
2
3
4
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相关目录并配置权限

1
2
3
4
5
6
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}
chown -R mysql.mysql /var/run/mysqld{3306,3307}
mkdir -p /var/lib/mysqld{3306,3307}
chown -R mysql.mysql /var/lib/mysqld{3306,3307}

5、创建mysql.sock文件

1
touch /tmp/mysql{3306,3307}.sock

解压MySQL

1、使用xftp上传mysql-5.6.34.tar.gz到CentOS服务器。
2、tar -zxvf mysql-5.6.34.tar.gz,解压mysql。

编译安装MySQL

1、cd mysql-5.6.34,进入mysql源文件目录。
2、配置编译。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql3307 \
-DMYSQL_DATADIR=/usr/local/mysql3307/data \
-DSYSCONFDIR=/usr/local/mysql3307/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_TCP_PORT=3307 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_SSL=system

3、编译安装

1
2
make
make install

这一步时间较长,请耐心等待。

配置MySQL

1、拷贝模板,作为配置文件。

1
cp /usr/local/mysql3307/support-files/my-default.cnf /usr/local/mysql3307/etc/my.cnf

2、设置开机启动。

1
cp /usr/local/mysql3307/support-files/mysql.server /etc/init.d/mysqld3307

3、修改my.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
# 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 = /usr/local/mysql3307
datadir = /usr/local/mysql3307/data
port = 3307
# server_id = .....
socket = /tmp/mysql3307.sock

# Remove leading # to set options mainly useful for reporting servers.

4、初始化mysql数据库。

1
/usr/local/mysql3307/scripts/mysql_install_db --basedir=/usr/local/mysql3307 --datadir=/usr/local/mysql3307/data --user=mysql

启动MySQL

1、启动mysql
service mysqld3307 start

2、设置超级管理员密码
/usr/local/mysql3307/bin/mysqladmin -u root password voidking -S /tmp/mysql3307.sock

3、登录mysql
mysql -u root -p -S /tmp/mysql3307.sock,然后输入密码voidking,成功登录mysql5.6。

至此,多版本mysql安装配置成功!

远程连接

1、关闭防火墙
systemctl stop firewalld.service

2、登录mysql控制台:
mysql> grant all privileges on *.* to 'root'@'%' identified by 'voidking' with grant option;

书签

MySQL之——Centos中安装多个mysql数据库的配置实例
http://blog.csdn.net/l1028386804/article/details/48368937

centos6.5 MySQL多实例安装与配置
http://jingyan.baidu.com/article/9faa723187a5ab473c28cba8.html

centos编译安装mysql 5.6及安装多个mysql实例
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=29792372&id=5759878

centos7安装运行多个mysql实例笔记
https://my.oschina.net/hollowj/blog/796146