centos7.4 mysql 5.7.20 源码安装

Posted

tags:

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

1. 安装依赖

yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git  ncurses-devel

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20.tar.gz

wget https://zh.osdn.net/projects/sfnet_boost/downloads/boost/1.59.0/boost_1_59_0.tar.gz/


2. 解压编译安装

[[email protected] ~]# tar xf mysql-5.7.20.tar.gz

[[email protected] ~]# mv boost_1_59_0.tar.gz mysql-5.7.20

[[email protected] ~]# cd mysql-5.7.20

[[email protected] mysql-5.7.20]# mkdir configure

[[email protected] mysql-5.7.20]# cd configure

[[email protected] configure]# cmake .. -DBUILD_CONFIG=mysql_release

-DINSTALL_LAYOUT=STANDALONE

-DCMAKE_BUILD_TYPE=RelWithDebInfo

-DENABLE_DTRACE=OFF

-DWITH_EMBEDDED_SERVER=OFF

-DWITH_INNODB_MEMCACHED=ON

-DWITH_SSL=bundled

-DWITH_ZLIB=system

-DWITH_PAM=ON

-DCMAKE_INSTALL_PREFIX=/var/mysql/

-DINSTALL_PLUGINDIR="/var/mysql/lib/plugin"

-DDEFAULT_CHARSET=utf8

-DDEFAULT_COLLATION=utf8_general_ci

-DWITH_EDITLINE=bundled

-DFEATURE_SET=community

-DCOMPILATION_COMMENT="MySQL Server (GPL)"

-DWITH_DEBUG=OFF

-DWITH_BOOST=..

[[email protected] configure]# make

[[email protected] configure]# make install                   # 此步骤很慢


3. 创建配置文件目录及用户

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

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

[[email protected] ~]# mkdir -p /var/mysql/log

[[email protected] ~]# chown -R mysql:mysql /data/mysql/

[[email protected] ~]# chown -R mysql:mysql /var/mysql/log


4. 修改配置文件

[[email protected] ~]# vim /etc/my.cnf

...

[mysqld]

datadir=/data/mysql

socket=/var/lib/mysql/mysql.sock

log_error=/var/mysql/log/error.log

basedir=/var/mysql


5. 初始化

[[email protected] ~]# /var/mysql/bin/mysqld --initialize --user=mysql

[[email protected] ~]# ll /data/mysql/

total 110628

-rw-r-----. 1 mysql mysql       56 Jul 10 17:51 auto.cnf

-rw-r-----. 1 mysql mysql      419 Jul 10 17:51 ib_buffer_pool

-rw-r-----. 1 mysql mysql 12582912 Jul 10 17:51 ibdata1

-rw-r-----. 1 mysql mysql 50331648 Jul 10 17:51 ib_logfile0

-rw-r-----. 1 mysql mysql 50331648 Jul 10 17:51 ib_logfile1

drwxr-x---. 2 mysql mysql     4096 Jul 10 17:51 mysql

drwxr-x---. 2 mysql mysql     8192 Jul 10 17:51 performance_schema

drwxr-x---. 2 mysql mysql     8192 Jul 10 17:51 sys

[[email protected] ~]# ll /var/mysql/log/

total 4

-rw-r-----. 1 mysql mysql 802 Jul 10 17:51 error.log



6. 修改配置文件

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

[[email protected] ~]# vim /etc/init.d/mysqld    #找到如下两行

...

basedir=/var/mysql/

datadir=/data/mysql

...

[[email protected] ~]# mkdir -p /var/lib/mysql

[[email protected] ~]# chown -R mysql:mysql /var/lib/mysql


7. 添加环境变量

[[email protected] mysql]# vim /etc/profile

...

MYSQL_HOME=/var/mysql/bin/

PATH=$PATH:$MYSQL_HOME

[[email protected] ~]# source /etc/profile


8 . 修改原始密码

[[email protected] ~]# cat /var/mysql/log/error.log | grep generated

2018-07-10T09:51:31.365809Z 1 [Note] A temporary password is generated for [email protected]: pS:SCG1goPhj

[[email protected] ~]# /etc/init.d/mysqld start

[[email protected] ~]# ln -s /var/lib/mysql/mysql.sock /tmp/

[[email protected] ~]# mysql -uroot -p

密码为: pS:SCG1goPhj

mysql> alter user 'root'@'localhost' identified by '123123';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)


以上是关于centos7.4 mysql 5.7.20 源码安装的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7.4 源码编译安装LNMP

CentOS 7.4使用yum源安装MySQL 5.7.20

Linux—Centos7.4之搭建Mysql数据库主从同步读写分离

mysql-5.7.20源码安装 + 多实例 + 主从复制

centos7.4 mysql5.6 源码安装

学习笔记-centos7.4下mysql编译安装