MySQL5.7.17源码编译安装与配置
一、下載MySQL源碼
官網(wǎng): http://www.mysql.com
下載下來的文件為:mysql-boost-5.7.17.tar.gz
二、解壓源碼,準(zhǔn)備環(huán)境
[root@server1 software]# tar -zxf mysql-boost-5.7.17.tar.gz [root@server1 software]# ls [root@server1 software]# cd mysql-5.7.17/ [root@server1 mysql-5.7.17]# ls [root@server1 mysql-5.7.17]# vim README [root@server1 mysql-5.7.17]# vim INSTALL幫助文檔里給我們的是一個(gè)網(wǎng)址,打開看看
可以用cmake的方式,這里我們看到這里只列出了幾個(gè)選項(xiàng),更多選項(xiàng)又被鏈接到了另外一個(gè)網(wǎng)址,打開看看
這么多選項(xiàng),我們根據(jù)需要進(jìn)行選擇,先看看從cmake –help
這就尷尬了,沒有安裝cmake,看看本機(jī)yum源里的cmake版本
cmake跨平臺(tái)工具是用來預(yù)編譯mysql源碼的,用于設(shè)置mysql的編譯參數(shù)。如:安裝目錄、數(shù)據(jù)存放目錄、字符編碼、排序規(guī)則等。所以安裝yum源里帶的即可
[root@server1 mysql-5.7.17]# yum install -y cmake.x86_64- 1
cmake –help似乎沒提供什么我們需要的選項(xiàng),還是參照mysql的官方文檔來吧
編譯環(huán)境
官方文檔說明:http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
從官方文檔知:需要以下依賴庫
- make 3.75
- mysql源代碼是由C和C++語言編寫,在linux下使用make對(duì)源碼進(jìn)行編譯和構(gòu)建,要求必須安裝make 3.75或以上版本
- gcc4.4.6
- GCC是Linux下的C語言編譯工具,mysql源碼編譯完全由C和C++編寫,要求必須安裝GCC4.4.6或以上版本
- Boost1.59.0
- mysql源碼中用到了C++的Boost庫,要求必須安裝boost1.59.0或以上版本
- bison2.1
- Linux下C/C++語法分析器
- ncurses
- 字符終端處理庫
由于我們下載的源碼包含boost,所以我們只需要安裝其他的依賴庫即可
- 字符終端處理庫
- 1
依賴庫安裝好了,我們將boost移至/usr/local下,方便使用
[root@server1 mysql-5.7.17]# cp -r boost/boost_1_59_0/ /usr/local/ [root@server1 mysql-5.7.17]# ls /usr/local/boost_1_59_0/ boost由于是源碼安裝,不同于玉米安裝,不會(huì)自動(dòng)幫我們創(chuàng)建用戶,所以需要我們創(chuàng)建用戶
[root@server1 mysql-5.7.17]# groupadd mysql #添加mysql用戶組 [root@server1 mysql-5.7.17]# useradd -r -g mysql -s /bin/false mysql #添加mysql用戶- 1
- 2
三、編譯安裝
配置mysql預(yù)編譯參數(shù)
參考mysql官方文檔說明:http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html#cmake-general-options
[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/usr/local/boost_1_59_0/ -DSYSCONFDIR=/etc -DEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all- DCMAKE_INSTALL_PREFIX:安裝路徑
- DMYSQL_DATADIR:數(shù)據(jù)存放目錄
- DWITH_BOOST:boost源碼路徑
- DSYSCONFDIR:my.cnf配置文件目錄
- DEFAULT_CHARSET:數(shù)據(jù)庫默認(rèn)字符編碼
- DDEFAULT_COLLATION:默認(rèn)排序規(guī)則
- DENABLED_LOCAL_INFILE:允許從本文件導(dǎo)入數(shù)據(jù)
- DEXTRA_CHARSETS:安裝所有字符集
預(yù)編譯報(bào)錯(cuò),提示remove CMakeCache.txt ,redhat還需要ncurses-devel , yum 安裝之
繼續(xù)執(zhí)行cmake預(yù)編譯
編譯并安裝
[root@server1 mysql-5.7.17]# make ##可加參數(shù)-j根據(jù)CPU核數(shù)指定編譯時(shí)的線程數(shù),可以加快編譯速度。默認(rèn)為1個(gè)線程編譯,經(jīng)測試四核CPU,2G的內(nèi)存,單先程編譯完需要20分鐘左右。 [root@server1 mysql-5.7.17]# makeinstall
至此,編譯安裝完成,下面進(jìn)行簡單的配置使用
mysql簡單配置
初始化系統(tǒng)數(shù)據(jù)庫
[root@server1 mysql-5.7.17]# cd /usr/local/mysql/ [root@server1 mysql]# ll -d drwxr-xr-x 10 root root 4096 Sep 23 22:45 . [root@server1 mysql]# chown -R mysql:mysql . [root@server1 mysql]# ll -d drwxr-xr-x 10 mysql mysql 4096 Sep 23 22:45 . [root@server1 mysql]# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2017-09-24T03:01:29.063554Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-09-24T03:01:29.068209Z 0 [ERROR] COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'latin1' 2017-09-24T03:01:29.068253Z 0 [ERROR] Aborting提示字符集有錯(cuò)
[root@server1 mysql]# vim /etc/my.cnf ##編輯:增加兩個(gè)編碼變量 #改成如下,如果沒有該文件,可拷貝一份,命令如下 ##cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cn[client] default-character-set=gbk ##增加的編碼變量 [mysqld] character_set_server=gbk ##增加的編碼變量 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql在初始化即可
如果使用–initialize參數(shù)初始化系統(tǒng)數(shù)據(jù)庫之后,會(huì)在~/.mysql_secret文件中生成root用戶的一個(gè)臨時(shí)密碼,同時(shí)也在初始化日志中打印出來了,如下圖(fy<;iif!U95r):
配置mysql服務(wù)并啟動(dòng)服務(wù)
[root@server1 init.d]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@server1 init.d]# chkconfig --add mysqld ## 添加到系統(tǒng)服務(wù) [root@server1 init.d]# chkconfig mysqld on ## 開機(jī)啟動(dòng) [root@server1 ~]# /etc/init.d/mysqld ##查看提供哪些用法 Usage: mysqld {start|stop|restart|reload|force-reload|status} [ MySQL server options ] [root@server1 ~]# /etc/init.d/mysqld start ##測試開啟服務(wù) Starting MySQL. SUCCESS! [root@server1 ~]# /etc/init.d/mysqld stop ##測試停止服務(wù) Shutting down MySQL. SUCCESS! [root@server1 ~]# /etc/init.d/mysqld start ##開啟服務(wù) [root@server1 ~]# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql ##添加軟鏈接將mysql加入系統(tǒng)環(huán)境變量,或者通過配置環(huán)境變量,export PATH=/usr/local/mysql/bin:$PATH 或者vim /etc/profile測試啟動(dòng)
[root@server1 ~]# mysql -uroot -pfy<;iif!U95r ##密碼為剛才初始化時(shí)生成的 -bash: !U95r: event not found ##秘密包含特殊字符,不能這樣寫 [root@server1 ~]# mysql -uroot -p Enter password: ##輸入密碼 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) ##報(bào)錯(cuò) [root@server1 ~]# ln -s /var/lib/mysql/mysql.sock /tmp ##軟鏈接 [root@server1 ~]# mysql -uroot -p ##再來 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.17 Copyright (c) 2000, 2016, 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> ##登陸成功設(shè)置數(shù)據(jù)庫密碼
mysql> set password for root@localhost=password('mypasswd'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> mysql> exit Bye [root@server1 ~]# mysql -uroot -pmypasswd mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.7.17 Source distribution Copyright (c) 2000, 2016, 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>修改成功,可以進(jìn)行數(shù)據(jù)庫的操作了
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)mysql> CREATE database mydatabase -> ; Query OK, 1 row affected (0.00 sec) mysql> SHOW databases -> ; +--------------------+ | Database | +--------------------+ | information_schema | | mydatabase | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) mysql> use mydatabase Database changed mysql> show tables -> ; Empty set (0.00 sec) mysql>轉(zhuǎn)載于:https://www.cnblogs.com/changxr/p/8525924.html
總結(jié)
以上是生活随笔為你收集整理的MySQL5.7.17源码编译安装与配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: requests发送http请求
- 下一篇: linux cmake编译源码,linu