溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

MySQL5.7.16源碼編譯安裝的過(guò)程

發(fā)布時(shí)間:2021-08-30 11:40:36 來(lái)源:億速云 閱讀:162 作者:chen 欄目:MySQL數(shù)據(jù)庫(kù)

這篇文章主要講解了“MySQL5.7.16源碼編譯安裝的過(guò)程”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“MySQL5.7.16源碼編譯安裝的過(guò)程”吧!

安裝環(huán)境:CentOS7 64位

一、系統(tǒng)安裝條件

官方文檔說(shuō)明: 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++語(yǔ)言編寫(xiě),在linux下使用make對(duì)源碼進(jìn)行編譯和構(gòu)建,要求必須安裝make 3.75或以上版本

3> gcc4.4.6

GCC是Linux下的C語(yǔ)言編譯工具,mysql源碼編譯完全由C和C++編寫(xiě),要求必須安裝GCC4.4.6或以上版本

4> Boost1.59.0

mysql源碼中用到了C++的Boost庫(kù),要求必須安裝boost1.59.0,如果版本不匹配,會(huì)報(bào)錯(cuò),導(dǎo)致編譯失敗。編譯時(shí)用參數(shù)WITH_BOOST指定源碼位置。

5>充足的內(nèi)存

當(dāng)編譯大型源文件時(shí),如果內(nèi)存不足,可能會(huì)遇到“internal compiler error”錯(cuò)誤

6>Perl

如果你想運(yùn)行測(cè)試腳本的話,就需要Perl

7> bison2.1

Linux下C/C++語(yǔ)法分析器, 如果遇到問(wèn)題,請(qǐng)升級(jí)到以后的版本,而不是恢復(fù)到以前的版本。

8> ncurses ncurses-devel

字符終端處理庫(kù)

所以在安裝前,需先檢查相關(guān)的依賴庫(kù):

rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" \

cmake \

make \

gcc \

ncurses \

ncurses-devel \

bison \

  | grep "not installed"

yum -y install 安裝需要的包

下載 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

如果沒(méi)安裝git客戶端,執(zhí)行yum install -y git安裝。 

MySQL5.7.16源碼編譯安裝的過(guò)程

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為例。

三、安裝

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ù)庫(kù)默認(rèn)字符編碼

  • -DDEFAULT_COLLATION:默認(rèn)排序規(guī)則

  • -DENABLED_LOCAL_INFILE:允許從本文件導(dǎo)入數(shù)據(jù)

  • -DEXTRA_CHARSETS:安裝所有字符集

如果cmake失敗,需要?jiǎng)h除掉已經(jīng)生成的 CMakeCache.txt文件.

更多預(yù)編譯配置參數(shù)請(qǐng)參考mysql官方文檔說(shuō)明: 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)測(cè)試單核CPU,1G的內(nèi)存,編譯完需要將近1個(gè)小時(shí)。

4> 初始化系統(tǒng)數(shù)據(jù)庫(kù)

shell> cd /usr/local/mysql

創(chuàng)建一個(gè)目錄,其位置可以提供給secure_file_priv系統(tǒng)變量, 該變量將導(dǎo)入/導(dǎo)出操作限制到該特定目錄

shell> mkdir mysql-files

shell> chmod 750 mysql-files

shell> chown -R mysql:mysql mysql-files

# 注意:MySQL 5.7.6之前的版本執(zhí)行這個(gè)腳本初始化系統(tǒng)數(shù)據(jù)庫(kù)

shell> ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

# 5.7.6之后版本初始系統(tǒng)數(shù)據(jù)庫(kù)腳本(本文使用此方式初始化)

shell> ./mysqld --initialize --user=mysql

2018-10-26T08:53:47.890293Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-10-26T08:53:47.891867Z 0 [ERROR] COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'latin1'

2018-10-26T08:53:47.892012Z 0 [ERROR] Aborting

發(fā)現(xiàn)報(bào)錯(cuò),解決方法是在配置文件中添加編碼參數(shù):

[client]

default-character-set = utf8    #新添加的參數(shù)

[mysqld]

basedir = /opt/app/mysql/mysql5716

datadir = /opt/app/mysql/mysql5716/data

port = 3306

socket = /opt/app/mysql/mysql5716/mysqld.sock

character-set-server = utf8    #新添加的參數(shù)

添加后重新初始化即可。初始化后,mysql會(huì)創(chuàng)建'root'@'localhost'賬號(hào)用于登錄。

# 初始化SSL

shell> ./bin/mysql_ssl_rsa_setup

注意:如果使用–initialize參數(shù)初始化系統(tǒng)數(shù)據(jù)庫(kù)之后,會(huì)在~/.mysql_secret文件中生成root用戶的一個(gè)臨時(shí)密碼,同時(shí)也在初始化日志中打印出來(lái)了,如下圖紅圈中所示: 

MySQL5.7.16源碼編譯安裝的過(guò)程

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 # 開(kāi)機(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ù)

或者

shell> bin/mysqld_safe --user=mysql &

如果啟動(dòng)出錯(cuò),查看error log解決,默認(rèn)為data directory下的host_name.err文件。

8、登錄后重置數(shù)據(jù)庫(kù)密碼

初始化后生成的默認(rèn)密碼必須重置后才能使用mysql

shell>alter user 'root'@'localhost' identified by 'xxx';

9、配置mysql環(huán)境變量

shell> vi /etc/profile

shell> export PATH=/usr/local/mysql/bin:$PATH

shell> source /etc/profile

感謝各位的閱讀,以上就是“MySQL5.7.16源碼編譯安裝的過(guò)程”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)MySQL5.7.16源碼編譯安裝的過(guò)程這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI