源码编译安装Mysql5.7版本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了源码编译安装Mysql5.7版本相关的知识,希望对你有一定的参考价值。

1、源码编译安装mysql(5.7版本)

下载地址:

https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz

#(MySQL从5.7版本之后,boost是必须的,建议把系统自带的boost库卸载,源码编译安装高版本

Boost库是为C++语言标准库提供扩展的一些C++程序库的总称

(1)环境准备:

[[email protected] ~]# ls

mysql-boost-5.7.18.tar.gz  nginx-1.10.3.tar.gz  nginx.conf  pcre-8.38.tar.gz  php-7.0.18.tar.gz

 

#卸载系统自带boots库

[[email protected] ~]# yum -y remove boost-*  

#卸载系统自带的mysql

[[email protected] ~]#  yum -y remove mysql

[[email protected] ~]# rpm -qa | grep mysql

mysql-libs-5.1.73-5.el6_6.x86_64

[[email protected] ~]#  rpm -e --nodeps  mysql-libs-5.1.73-5.el6_6.x86_64

[[email protected] ~]# rpm -qa | grep mysql

#安装必要的资源包

建议使用网络yum源,RHEL6.5光盘中自带的软件包版本不够,mysql-boost-5.7.18.tar.gz的编译对软件包的版本要求比较高,其中cmake的版本要不低于2.8

#安装依赖包

[[email protected] ~]# yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel

 

(2)添加用户和组

[[email protected] ~]# groupadd mysql

[[email protected] ~]# useradd -M -s /sbin/nologin -r -g mysql mysql

 

(3)创建安装目录和数据存放目录

[[email protected] ~]# mkdir -p /server/mysql

 

(4)上传源码包 并解压源码包

[[email protected] LAMP]# ls

技术分享图片

 

[[email protected] ~]# tar zxf mysql-boost-5.7.18.tar.gz -C /server/

 

(5)将boost移到/server/

技术分享图片 

[[email protected] server]# cd mysql-5.7.18/   (包含boost库的文件)

技术分享图片 

#将boots文件移动到/server/mysql/下

[[email protected] mysql-5.7.18]# mv boost/ /server/mysql

[[email protected] mysql-5.7.18]# cd /server/mysql

[[email protected] mysql]# ls

boost

 

(6)配置参数

[[email protected] mysql]# cd ../

[[email protected] server]# ls

mysql  mysql-5.7.18

[[email protected] server]# cd mysql-5.7.18/

[[email protected] mysql-5.7.18]#cmake -DCMAKE_INSTALL_PREFIX=/server/mysql  -DMYSQL_DATADIR=/server/mysql/data -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/server/mysql/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=l -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/server/mysql/boost

技术分享图片

这些编译参数的帮助寻找方法:

http://www.mysql.com→→Documentation→→选择对应的版本(5.7)Installation & Upgrades→→Installing MySQL from Source →→MySQL Source-Configuration Options

最终的URL https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html               

 

DCMAKE_INSTALL_PREFIX:指定MySQL程序的安装目录,默认/usr/local/mysql
DEFAULT_CHARSET:指定服务器默认字符集,默认latin1
DEFAULT_COLLATION:指定服务器默认的校对规则,默认latin1_general_ci
ENABLED_LOCAL_INFILE:指定是否允许本地执行LOAD DATA INFILE,默认OFF
WITH_COMMENT:指定编译备注信息
WITH_xxx_STORAGE_ENGINE:指定静态编译到mysql的存储引擎,MyISAM,MERGE,MEMBER以及CSV四种引擎默认即被编译至服务器,不需要特别指定。
WITHOUT_xxx_STORAGE_ENGINE:指定不编译的存储引擎
SYSCONFDIR:初始化参数文件目录
MYSQL_DATADIR:数据文件目录
MYSQL_TCP_PORT:服务端口号,默认3306
MYSQL_UNIX_ADDR:socket文件路径,默认/tmp/mysql.sock

 

编译

mysql-5.7.18.tar.gz编译时会占用大量的系统资源,建议使用多个核心同时进行编译,否则可能会编译失败

 

(7)编译

#查看服务器cpu数

[[email protected] mysql-5.7.18]# grep processor /proc/cpuinfo | wc -l

2

[[email protected] mysql-5.7.18]# make -j 2


(8)安装

[[email protected] mysql-5.7.18]# make install


 

(9)修改目录权限

[[email protected] mysql-5.7.18]# chown -R mysql:mysql /server/mysql/

 

(10)生成配置文件

#将原服务器配置文件移动备份或删除

[[email protected] mysql-5.7.18]# mv /etc/my.cnf{,.bak}

 

#因5.7版本无此配置模板文件/server/mysql/support-files/my-default.cnf   

#自行编写my.cnf文件

[[email protected] mysql-5.7.18]#vim /etc/my.cnf

[mysqld]

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#default

user = mysql

basedir = /server/mysql

datadir = /server/mysql/data

port = 3306

pid-file = /server/mysql/data/mysql.pid

socket = /server/mysql/mysql.sock

character-set-server=utf8

[client]

socket = /server/mysql/mysql.sock

 

(11)生成服务启动脚本

grep chkconfig ./* -R  -color

技术分享图片

[[email protected] mysql]# cp /server/mysql/support-files/mysql.server /etc/init.d/mysqld

[[email protected] mysql]# chmod +x /etc/init.d/mysqld

[[email protected] mysql]# chkconfig --add mysqld

[[email protected] mysql]# chkconfig mysqld on

[[email protected] mysql]# chkconfig --list mysqld

mysqld            0:off       1:off       2:on 3:on 4:on 5:on 6:off

 

(12)初始化数据库

[[email protected] mysql]# /server/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/server/mysql --datadir=/server/mysql/data  

技术分享图片

 

(13)启动服务

[[email protected] mysql]# service mysqld restart

 ERROR! MySQL server PID file could not be found!

Starting MySQL.Logging to '/server/mysql/data/Wg64.err'.

 SUCCESS!

[[email protected] mysql]# service mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

 

(15)优化调用命令路径

#添加path路径: vim /etc/profile 添加下面2行 在文件的结尾

export MYSQL_HOME=/server/mysql

export PATH=$PATH:$MYSQL_HOME/bin

技术分享图片

#使修改生效

source /etc/profile

 

[[email protected] mysql]# ln -s /server/mysql/bin/* /usr/local/bin/

 

 

(14)修改mysql密码测试登入:

 

[[email protected] ~]# mysqladmin -u root password "123456"

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

测试登入成功:

技术分享图片

 

 

源码编译LNMP请参考链接:http://blog.51cto.com/13719714/2110940

源码编译LAMP请参考链接:http://blog.51cto.com/13719714/2109227

Apache基础调优请参考链接:http://blog.51cto.com/13719714/2109007


以上是关于源码编译安装Mysql5.7版本的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu上源码编译安装mysql5.7.27

MYSQL5.7源码包编译安装

源码编译并二进制安装MySQL5.7 3 二进制安装mariadb10.4

centos7.x编译安装mysql5.7.16

ubuntu编译安装mysql5.7

速看!centos7下源码安装mysql5.7