MySQL 5.7.13 源碼編譯安裝配置方法圖文教程
安裝環(huán)境:CentOS7 64位 MINI版
官網(wǎng)源碼編譯安裝文檔:http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
一、系統(tǒng)安裝條件
官方文檔說明:http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
1> cmake
MySQL使用cmake跨平臺(tái)工具預(yù)編譯源碼,用于設(shè)置mysql的編譯參數(shù)。如:安裝目錄、數(shù)據(jù)存放目錄、字符編碼、排序規(guī)則等。安裝最新版本即可。
2> make3.75
mysql源代碼是由C和C++語言編寫,在linux下使用make對(duì)源碼進(jìn)行編譯和構(gòu)建,要求必須安裝make 3.75或以上版本
3> gcc4.4.6
GCC是Linux下的C語言編譯工具,mysql源碼編譯完全由C和C++編寫,要求必須安裝GCC4.4.6或以上版本
4> Boost1.59.0
mysql源碼中用到了C++的Boost庫,要求必須安裝boost1.59.0或以上版本
5> bison2.1
Linux下C/C++語法分析器
6> ncurses
字符終端處理庫
所以在安裝前,需先安裝相關(guān)的依賴庫:
shell> sudo yum install -y cmake,make,gcc,gcc-c++,bison, ncurses,ncurses-devel
下載Boost1.59.0源代碼,并解壓到/usr/local/目錄下:
shell> wget -O https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz shell> tar -zxvf boost_1_59_0.tar.gz -C /usr/local/
二、下載MySQL源碼
從github上下載mysql的源碼
shell> cd /opt shell> git clone https://github.com/mysql/mysql-server.git shell> ls mysql-server
如果沒安裝git客戶端,執(zhí)行yum install -y git安裝。
shell> git branch -r origin/5.5 origin/5.6 origin/5.7 origin/HEAD -> origin/5.7 origin/cluster-7.2 origin/cluster-7.3 origin/cluster-7.4 origin/cluster-7.5
當(dāng)前分支默認(rèn)為5.7版本,如果要安裝其它版本,切換到相應(yīng)的分支即可。如安裝5.6版本:git checkout 5.6,這里以安裝5.7為例。
搜狐鏡像下載地址:
http://mirrors.sohu.com/mysql/MySQL-5.5/
http://mirrors.sohu.com/mysql/MySQL-5.6/
http://mirrors.sohu.com/mysql/MySQL-5.7/
三、安裝
1> 添加mysql用戶
shell> cd /opt/mysql-server shell> groupadd mysql #添加mysql用戶組 shell> useradd -r -g mysql -s /bin/false mysql #添加mysql用戶
2> 配置mysql預(yù)編譯參數(shù)
shell> 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ù)編譯配置參數(shù)請(qǐng)參考mysql官方文檔說明:http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html#cmake-general-options
3> 編譯并安裝
shell> make -j `grep processor /proc/cpuinfo | wc -l` shell> make install
-j參數(shù)表示根據(jù)CPU核數(shù)指定編譯時(shí)的線程數(shù),可以加快編譯速度。默認(rèn)為1個(gè)線程編譯,經(jīng)測試單核CPU,1G的內(nèi)存,編譯完需要將近1個(gè)小時(shí)。
4> 初始化系統(tǒng)數(shù)據(jù)庫
shell> cd /usr/local/mysql shell> chown -R mysql:mysql . # 注意:MySQL 5.7.6之前的版本執(zhí)行這個(gè)腳本初始化系統(tǒng)數(shù)據(jù)庫 shell> ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data # 5.7.6之后版本初始系統(tǒng)數(shù)據(jù)庫腳本(本文使用此方式初始化) shell> ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data shell> ./bin/mysql_ssl_rsa_setup shell> chown -R root . shell> chown -R mysql data
注意:如果使用–initialize參數(shù)初始化系統(tǒng)數(shù)據(jù)庫之后,會(huì)在~/.mysql_secret文件中生成root用戶的一個(gè)臨時(shí)密碼,同時(shí)也在初始化日志中打印出來了,如下圖紅圈中所示:
5、配置文件及參數(shù)優(yōu)化
shell> cp support-files/my-default.cnf /etc/my.cnf shell> vim /etc/my.cnf [client] port=3306 socket=/usr/local/mysql/mysql.sock [mysqld] character-set-server=utf8 collation-server=utf8_general_ci skip-external-locking skip-name-resolve user=mysql port=3306 basedir=/usr/local/mysql datadir=/usr/local/mysql/data tmpdir=/usr/local/mysql/temp # server_id = ..... socket=/usr/local/mysql/mysql.sock log-error=/usr/local/mysql/logs/mysql_error.log pid-file=/usr/local/mysql/mysql.pid open_files_limit=10240 back_log=600 max_connections=500 max_connect_errors=6000 wait_timeout=605800 #open_tables=600 #table_cache = 650 #opened_tables = 630 max_allowed_packet=32M sort_buffer_size=4M join_buffer_size=4M thread_cache_size=300 query_cache_type=1 query_cache_size=256M query_cache_limit=2M query_cache_min_res_unit=16k tmp_table_size=256M max_heap_table_size=256M key_buffer_size=256M read_buffer_size=1M read_rnd_buffer_size=16M bulk_insert_buffer_size=64M lower_case_table_names=1 default-storage-engine=INNODB innodb_buffer_pool_size=2G innodb_log_buffer_size=32M innodb_log_file_size=128M innodb_flush_method=O_DIRECT ##################### thread_concurrency=32 long_query_time=2 slow-query-log=on slow-query-log-file=/usr/local/mysql/logs/mysql-slow.log [mysqldump] quick max_allowed_packet=32M [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
6、配置mysql服務(wù)
shell> cp support-files/mysql.server /etc/init.d/mysqld shell> chkconfig --add mysqld # 添加到系統(tǒng)服務(wù) shell> chkconfig mysqld on # 開機(jī)啟動(dòng)
7、啟動(dòng)服務(wù)
shell> service mysqld start # 啟動(dòng)mysql服務(wù) shell> service mysqld stop # 停止mysql服務(wù) shell> service mysqld restart # 重新啟動(dòng)mysql服務(wù)
8、設(shè)置數(shù)據(jù)庫密碼
shell> /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by "root" with grant option;" shell> /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by "root" with grant option;" # 開啟遠(yuǎn)程登錄(將host設(shè)為%即可) /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'%' identified by "root" with grant option;"
9、配置mysql環(huán)境變量
shell> vim /etc/profile shell> export PATH=/usr/local/mysql/bin:$PATH shell> source /etc/profile
四、其它注意事項(xiàng)
如果中途編譯失敗了,需要?jiǎng)h除cmake生成的預(yù)編譯配置參數(shù)的緩存文件和make編譯后生成的文件,再重新編譯。
shell> cd /opt/mysql-server shell> rm -f CMakeCache.txt shell> make clean
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
mysql中secure_file_priv=不生效問題及解決
這篇文章主要介紹了mysql中secure_file_priv=不生效問題及解決方案,以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家,2024-01-01MySQL數(shù)據(jù)庫遭到攻擊篡改(使用備份和binlog進(jìn)行數(shù)據(jù)恢復(fù))
這篇文章主要介紹了MySQL數(shù)據(jù)庫遭到攻擊篡改(使用備份和binlog進(jìn)行數(shù)據(jù)恢復(fù)),需要的朋友可以參考下2016-04-04Mysql四種分區(qū)方式以及組合分區(qū)落地實(shí)現(xiàn)詳解
對(duì)用戶來說,分區(qū)表是一個(gè)獨(dú)立的邏輯表,但是底層由多個(gè)物理子表組成,下面這篇文章主要給大家介紹了關(guān)于Mysql四種分區(qū)方式以及組合分區(qū)落地實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2022-04-04MySQL 8.0.18 Hash Join不支持left/right join左右連接問題
在MySQL 8.0.18中,增加了Hash Join新功能,它適用于未創(chuàng)建索引的字段,做等值關(guān)聯(lián)查詢。這篇文章給大家介紹MySQL 8.0.18 Hash Join不支持left/right join左右連接,感興趣的朋友一起看看吧2019-11-11Mysql中通用表達(dá)式WITH?AS語句的使用實(shí)例代碼
with as也叫子查詢,用來定義一個(gè)sql片段,且該片段會(huì)被整個(gè)sql語句反復(fù)使用很多次,這個(gè)sql片段就相當(dāng)于是一個(gè)公用臨時(shí)表,下面這篇文章主要給大家介紹了關(guān)于Mysql中通用表達(dá)式WITH?AS語句使用的相關(guān)資料,需要的朋友可以參考下2022-08-08mysql性能優(yōu)化腳本mysqltuner.pl使用介紹
無意中發(fā)現(xiàn)了,major哥們開發(fā)的一個(gè)性能分析腳本,很有意思,可以通過這個(gè)腳本學(xué)學(xué)他的思想2013-02-02Mysql中undo、redo與binlog的區(qū)別淺析
大家應(yīng)該都知道日志系統(tǒng)主要有redo log(重做日志)和binlog(歸檔日志),下面這篇文章主要給大家介紹了關(guān)于Mysql中undo、redo與binlog區(qū)別的相關(guān)資料,需要的朋友可以參考下2021-09-09