同机安装多个MySQL版本-MySQL 5.7源码安装流程详解

来源:互联网 发布:高德地图大数据发现 编辑:程序博客网 时间:2024/06/05 03:51

注意:
在同一台linux机器安装多个mysql版本方法:
先通过rpm包或者yum安装非源码版本,比如MySQL 5.1(端口号3306,本文中不会涉及);
通过源码包安装更多版本,比如MySQL 5.6(端口号3307),MySQL 5.7(端口号3308)。

本文主要描述同机多版本源码安装MySQL 5.7的具体步骤

一、官网下载

当前MySQL 5.7未发布GA版本,所以我们从github获取对应的rc版本。

1.1 安装文档参考:

https://dev.mysql.com/doc/refman/5.7/en/installing-development-tree.html

1.2 获取最新代码

代码位置: https://github.com/mysql/mysql-server
选在最新的5.7.8版本。

cd gitgit clone https://github.com/mysql/mysql-server.gitcd mysql-server/

此时,最新的代码已下载完毕。这里安装的是5.7.8-rc版本。

二、源码安装

2.1 cmake

cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql3308 \-DMYSQL_DATADIR=/var/lib/mysql3308 \-DSYSCONFDIR=/etc/mysql3308 \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/var/lib/mysql3308/mysql.sock \-DMYSQL_TCP_PORT=3308 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8mb4 \-DDEFAULT_COLLATION=utf8mb4_general_ci

注:

  • 问题1:cmake未安装或版本不匹配
    如果遇到本机未安装cmake或者cmake版本太低,例如,报错如下:
CMake Error at CMakeLists.txt:21 (CMAKE_MINIMUM_REQUIRED):  CMake 2.8.2 or higher is required.  You are running version 2.6.4
  • 解决方法:
    需要首先安装cmake:
yum install cmake
  • 问题2:boost版本不匹配
CMake Warning at cmake/boost.cmake:256 (MESSAGE):  Boost minor version found is 41 we need 58Call Stack (most recent call first):  CMakeLists.txt:429 (INCLUDE)    -- BOOST_INCLUDE_DIR /usr/include    -- LOCAL_BOOST_DIR    -- LOCAL_BOOST_ZIP    -- Could not find (the correct version of) boost.    -- MySQL currently requires boost_1_58_0
  • 解决方法:
    去官网下载最新的boost包:http://sourceforge.net/projects/boost/files/boost/
    根据具体错误提示,选择对应的版本下载。通过以上的错误提示,我们可以看到我们这里需要的版本是1.58.0.
    将下载的tar.gz包(如boost_1_58_0.tar.gz)上传,并解压。
tar -zxvf boost_1_58_0.tar.gz

将解压后的boost目录制定到cmake命令的-DWITH_BOOST参数中,-DWITH_BOOST=/home/username/download/boost_1_58_0,并重新执行cmake。

cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql3308 \-DMYSQL_DATADIR=/var/lib/mysql3308 \-DSYSCONFDIR=/etc/mysql3308 \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/var/lib/mysql3308/mysql.sock \-DMYSQL_TCP_PORT=3308 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8mb4 \-DDEFAULT_COLLATION=utf8mb4_general_ci \-DWITH_BOOST=/home/jinggang.sjg/download/boost_1_58_0

2.2 make, make install

sudo make -j n

:
为了加速make,建议在条件允许的情况下,尽量设置较大的-j参数以加快make速度。

sudo make install  

2.3 创建mysql用户,如已存在请忽略该步

useradd mysql

2.4 初始化:

cd /usr/local/mysql3308

mysql_install_db已不再推荐使用,改为mysqld –initialize

sudo bin/mysqld --basedir=/usr/local/mysql3308/ --datadir=/var/lib/mysql3308 --initialize-insecure
  • 问题:
$sudo bin/mysqld --basedir=/usr/local/mysql3308/ --datadir=/var/lib/mysql3308 --initialize-insecure2015-09-30T02:40:49.496690Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2015-09-30T02:40:49.499377Z 0 [ERROR] You have enabled the binary log, but you haven't provided the mandatory server-id. Please refer to the proper server start-up parameters documentation2015-09-30T02:40:49.499389Z 0 [ERROR] Aborting
  • 解决方法:
    此错误的原因是,在执行mysqld的过程中 疑似 读取了/etc/my.cnf中的配置,其中有配置log-bin。
    这里的解决方法之一,增加–server-id=0
$sudo bin/mysqld --basedir=/usr/local/mysql3308/ --datadir=/var/lib/mysql3308 --initialize-insecure --server-id=02015-09-30T02:43:53.959152Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2015-09-30T02:43:54.374358Z 0 [Warning] InnoDB: New log files created, LSN=457902015-09-30T02:43:54.453774Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2015-09-30T02:43:54.515917Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 172c4983-671d-11e5-9447-200bc79ee9c7.2015-09-30T02:43:54.516619Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2015-09-30T02:43:54.516949Z 0 [Warning] Failed to setup SSL2015-09-30T02:43:54.516958Z 0 [Warning] SSL error: SSL context is not usable without certificate and private key2015-09-30T02:43:54.517463Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

2.5 准备service启动程序mysql3308

将源码中support-files中的mysql.server复制到/etc/init.d/mysql3308

$sudo cp mysql.server /etc/init.d/mysql3308

并修改以下内容:

basedir=/usr/local/mysql3308datadir=/var/lib/mysql3308
sudo chkconfig --add mysql3308

2.6 准备配置文件my.cnf

  • 创建/etc/mysql3308/my.cnf
[mysqld]basedir=/usr/local/mysql3308datadir=/var/lib/mysql3308socket=/var/lib/mysql3308/mysql.sockuser=mysqlsymbolic-links=0default-storage-engine=INNODBcharacter-set-filesystem=utf8mb4init_connect='SET collation_connection = utf8mb4_general_ci'init_connect='SET NAMES utf8mb4'character-set-server=utf8mb4collation-server=utf8mb4_general_ciskip-character-set-client-handshaketransaction_isolation = READ-COMMITTEDserver-id=0[client][mysqld_safe]log-error=/var/log/mysqld3308.logpid-file=/var/run/mysqld/mysqld3308.pid

三、启动mysql5.7:

3.1 启动MySQL 5.7

sudo service mysql3308 restart

启动mysql3308时,感觉读取的配置文件是/etc/my.cnf + mysql3308/my.cnf,如果my.cnf里面有不支持5.7,需要注释掉。

3.2 修改root密码

修改root密码为root:

/usr/local/mysql3308/bin/mysqladmin  -uroot -p password 'root'

3.3 登陆mysql 5.7客户端

/usr/local/mysql3308/bin/mysql -uroot -proot -P3308

3.4 对访问进行授权

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' identified by '' REQUIRE NONE;flush privileges;

3.5 完成收工

$mysql -h127.0.0.1 -uroot -proot -P3308Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 21Server version: 5.7.8-rc Source distributionCopyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.This software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL v2 licenseType 'help;' or '\h' for help. Type '\c' to clear the current input statement.

四、参考资料

[1] http://blog.csdn.net/zhaoyangjian724/article/details/46330627

0 0
原创粉丝点击