1. 程式人生 > >mysql-5.7.23源碼編譯安裝

mysql-5.7.23源碼編譯安裝

-c mpat ora else temporary 文件 cte name remove

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 root@localhost: 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 ‘root@‘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源碼編譯安裝