mysql-5.7.23源码编译安装

Posted

tags:

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

mysql-5.7.23源码编译安装

1.下载源码

# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.23.tar.gz
# tar xf mysql-5.7.23.tar.gz

2.隐藏版本信息

隐藏版本信息是XX电信运营商提出的变态要求,经测试版本信息不能直接删除,否则编译出错,暂时修改为100.100.100

# cd mysql-5.7.23
# vim VERSION
MYSQL_VERSION_MAJOR=100
MYSQL_VERSION_MINOR=100
MYSQL_VERSION_PATCH=100
MYSQL_VERSION_EXTRA=

版本高于5.8版本报错

#error "show_compatibility_56 is to be removed in MySQL 5.8"

解决办法:

修改sql/mysqld.cc源代码,将下面的内容(346-352行)

#if MYSQL_VERSION_ID >= 50800
#error "show_compatibility_56 is to be removed in MySQL 5.8"
#else
/*
  Default value TRUE for the EMBEDDED_LIBRARY,
  default value from Sys_show_compatibility_56 otherwise.
*/
my_bool show_compatibility_56= TRUE;
#endif /* MYSQL_VERSION_ID >= 50800 */

修改为

//#if MYSQL_VERSION_ID >= 50800
//#error "show_compatibility_56 is to be removed in MySQL 5.8"
//#else
/*
  Default value TRUE for the EMBEDDED_LIBRARY,
  default value from Sys_show_compatibility_56 otherwise.
*/
my_bool show_compatibility_56= TRUE;
//#endif /* MYSQL_VERSION_ID >= 50800 */

然后重新编译即可。

3.下载编译需要的软件

# yum -y install gcc gcc-c++ cmake ncurses-devel bsion

4.编译mysql

编译过程中需要用到boost_1_59_0,因为没有安装,所以加上-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local

# cmake -DDOWNLOAD_BOOST=1   -DWITH_BOOST=/usr/local   -DCMAKE_INSTALL_PREFIX=/usr/local/mysql   -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock   -DDEFAULT_CHARSET=utf8   -DDEFAULT_COLLATION=utf8_general_ci   -DWITH_MYISAM_STORAGE_ENGINE=1   -DWITH_INNOBASE_STORAGE_ENGINE=1   -DENABLED_LOCAL_INFILE=1   -DMYSQL_DATADIR=/usr/local/mysql/data   -DMYSQL_TCP_PORT=3306

# make && make install

5.安装mysql

创建mysql用户和组
# groupadd -g 306 mysql
不需要登录也不需要创建家目录
# useradd -u 306 -g 306 -s /bin/false -M mysql 
# chown -R mysql:mysql /usr/local/mysql

初始化
# cd /usr/local/mysql
# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2>&1 | tee data/mysql_init.log
提示:启动时会生成初始密码,记得查看,忘记了可以查看文件data/mysql_init.log
设置开机启动
# cp support-files/mysql.server /etc/init.d/mysql
# chkconfig --add mysql 
# chkconfig mysql on
# service mysql start
# grep "temporary password" data/mysql_init.log
2018-10-13T05:25:14.146820Z 1 [Note] A temporary password is generated for [email protected]: f57d_Fp4(Hq#
配置环境变量
# cat > /etc/profile.d/mysql.sh <<EOF
export PATH=/usr/local/mysql/bin:$PATH
EOF
# source /etc/profile

6.验证mysql

# mysql -p
Enter password: 输入启动时生成的初始密码f57d_Fp4(Hq#
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 100.100.100

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.

mysql>
可以看到mysql已经启动正常,并且版本是我们自定义的版本信息
5.7版本mysql需要先修改用户密码才能进行下一步操作
mysql> alter user ‘[email protected]‘localhost‘ identified by ‘db.0easy.com‘;
Query OK, 0 rows affected (0.00 sec)
查看版本信息
mysql> select @@version;
+-------------+
| @@version   |
+-------------+
| 100.100.100 |
+-------------+
1 row in set (0.00 sec)

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

数据库mysql5.7 源码安装

windwos源码安装mysql

Win10 子系统 WSL 编译安装MySQL5.7

Mysql 5.7 安装及备份

centos 7 安装MySQL 5.7.23

CentOS 7 安装 MySQL 5.7.23