CentOS7编译安装mysql5.7.30

Mysql5.7版本更新后有很多变化,比如json等,连安装都有变化,他安装必须要Boost库,不过mysql的官网源码有带boost库的源码和不带boost库的源码两种,因此有两种安装方式,其实都是一样的,仅仅是不带boost库源码的需要单独安装boost。
那什么是boost库呢? Boost库是为C++语言标准库提供扩展的一些C++程序库的总称。

# 下载官方的带boost源码包mysql-boost-5.7.30.tar.gz
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.30.tar.gz

1. 安装依赖
# 先检查有没有安装过mysql或mariadb
rpm -qa |grep mysql
rpm -qa |grep mariadb
# 我有个mariadb-libs-5.5.56-2.el7.x86_64,把它给卸载了
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
# 以官方文档安装必备依赖:CMake、make 3.75或更高版本、ANSI C ++编译器、SSL库、Boost C ++库、ncurses相关、bison相关
yum install -y cmake make gcc gcc-c++ openssl openssl-devel ncurses ncurses-devel bison bison-devel

2. 安装MySQL
分两种情况说明:
2.1 带boost的mysql源码安装
软件包名称:mysql-boost-5.7.30.tar.gz
# tar zxvf mysql-boost-5.7.30.tar.gz
# cd mysql-5.7.30
# 使用cmake构建项目
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=ON \
-DWITH_MYISAM_STORAGE_ENGINE=ON \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_BOOST=./boost/boost_1_59_0
# 开始编译
make
# 开始安装
make install
# 若编译失败,解决问题后可清理重新编译(成功就不用运行了)
make clean
rm CMakeCache.txt

2.2 不带boot的mysql源码安装
软件包名称:
软件包名称: mysql-5.7.30.tar.gz
# tar zxvf mysql-5.7.30.tar.gz
在cmake过程中会下载boost_1_59_0.tar.gz到/usr/local/boost 目录下并解压该软件包,无需人为去下载该软件包
# 使用cmake构建项目
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EMBEDDED_SERVER=1
# 开始编译
make
# 开始安装
make install
# 若编译失败,解决问题后可清理重新编译(成功就不用运行了)
make clean
rm CMakeCache.txt

3、创建my.cnf配置文件
# vi /etc/my.cnf

[mysqld]
server-id=1
bind-address=0.0.0.0
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=20202
log_output=file
slow_query_log=on
slow_query_log_file=/usr/local/mysql/mysql-slow.log
log_queries_not_using_indexes=on
long_query_time=10
binlog_format=MIXED
log-bin=/usr/local/mysql/mysql-bin
expire_logs_days=15
max_binlog_size=500M
character-set-server=utf8
lower_case_table_names=1
general_log=1
general_log_file=/usr/local/mysql/mysql-query.log
pid-file=/usr/local/mysql/mysqld-pid
federated
max_connections=2000
character_set_server=utf8
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# # Settings user and group are ignored when systemd is used.
# # If you need to run mysqld under a different user or group,
# # customize your systemd unit file for mariadb according to the
# # instructions in http://fedoraproject.org/wiki/Systemd
show_compatibility_56=on

#
[client]
port=20202
socket=/tmp/mysql.sock
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysql-error.log

4、初始化mysql数据库
# groupadd mysql
# useradd -M -s /sbin/nologin -g mysql mysql
# chown -R mysql:mysql /usr/local/mysql/
# cd /usr/local/mysql/bin
# ./mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

5、mysql服务脚本配置
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# chmod +x /etc/init.d/mysqld
# /etc/init.d/mysqld start

6、设置mysql root用户密码
# /usr/local/mysql/bin/mysql -u root -p
mysql> use mysql;
mysql> select user,authentication_string,host from mysql.user;
mysql> update mysql.user set authentication_string=password("yang123") where user='root'and host='localhost';
mysql> flush privileges;

7、配置mysql环境变量
vi /etc/profile
# 在profile文件末尾增加两行
PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH
# 使PATH搜索路径立即生效:
source /etc/profile

8、关于mysql 5.7
myql 5.7和早期版本的区别如:
3倍更快的性能
InnoDB 相关改进
新的优化器
多源复制
GIS 相关改进
原生 JSON 支持,

相关新闻

联系我们

全国服务热线

400-033-9553

电子邮件:admin@example.com
工作时间:09:00-17:00 周一至周五

在线客服
关注微信
关注微信
分享本页
返回顶部