MySQL 5.7.13 源碼編譯裝置配置辦法圖文教程。本站提示廣大學習愛好者:(MySQL 5.7.13 源碼編譯裝置配置辦法圖文教程)文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL 5.7.13 源碼編譯裝置配置辦法圖文教程正文
裝置環境:CentOS7 64位 MINI版
官網源碼編譯裝置文檔:http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
一、零碎裝置條件
官方文檔闡明:http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
1> cmake
MySQL運用cmake跨平台工具預編譯源碼,用於設置mysql的編譯參數。如:裝置目錄、數據寄存目錄、字符編碼、排序規則等。裝置最新版本即可。
2> make3.75
mysql源代碼是由C和C++言語編寫,在linux下運用make對源碼停止編譯和構建,要求必需裝置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
字符終端處置庫
所以在裝置前,需先裝置相關的依賴庫:
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客戶端,執行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
以後分支默許為5.7版本,假如要裝置其它版本,切換到相應的分支即可。如裝置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預編譯參數
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:數據寄存目錄
-DWITH_BOOST:boost源碼途徑
-DSYSCONFDIR:my.cnf配置文件目錄
-DEFAULT_CHARSET:數據庫默許字符編碼
-DDEFAULT_COLLATION:默許排序規則
-DENABLED_LOCAL_INFILE:允許從本文件導入數據
-DEXTRA_CHARSETS:裝置一切字符集
更多預編譯配置參數請參考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參數表示依據CPU核數指定編譯時的線程數,可以放慢編譯速度。默許為1個線程編譯,經測試單核CPU,1G的內存,編譯完需求將近1個小時。
4> 初始化零碎數據庫
shell> cd /usr/local/mysql shell> chown -R mysql:mysql . # 留意:MySQL 5.7.6之前的版本執行這個腳本初始化零碎數據庫 shell> ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data # 5.7.6之後版本初始零碎數據庫腳本(本文運用此方式初始化) 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參數初始化零碎數據庫之後,會在~/.mysql_secret文件中生成root用戶的一個暫時密碼,同時也在初始化日志中打印出來了,如下圖紅圈中所示:
5、配置文件及參數優化
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服務
shell> cp support-files/mysql.server /etc/init.d/mysqld shell> chkconfig --add mysqld # 添加到零碎服務 shell> chkconfig mysqld on # 開機啟動
7、啟動服務
shell> service mysqld start # 啟動mysql服務 shell> service mysqld stop # 中止mysql服務 shell> service mysqld restart # 重新啟動mysql服務
8、設置數據庫密碼
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;" # 開啟近程登錄(將host設為%即可) /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'%' identified by "root" with grant option;"
9、配置mysql環境變量
shell> vim /etc/profile shell> export PATH=/usr/local/mysql/bin:$PATH shell> source /etc/profile
四、其它留意事項
假如中途編譯失敗了,需求刪除cmake生成的預編譯配置參數的緩存文件和make編譯後生成的文件,再重新編譯。
shell> cd /opt/mysql-server shell> rm -f CMakeCache.txt shell> make clean
以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支持。