咱們將學習如何 編譯 和 安裝 的 MySQL服務器 從源代碼。 以後,咱們將 配置 咱們的服務器和基本功能 安全 它用於通常用途。 最後,咱們將討論 基礎知識 的 MySQL服務器 。
安裝 MySQL服務器 從源代碼包括如下步驟。
1) - 1安裝缺乏的依賴項
3) 下載的源代碼
4) 解包和安裝
5) 後安裝過程
6) - 2日安裝缺乏的依賴項
7) 安裝檢查
在安裝 MySQL服務器 如下部分,建議查看。
http://howtolamp.com/lamp/mysql/5.6/installing/
1)安裝缺乏的依賴關係 Perl-GD 支持 MySQL服務器 須要安裝Perl-GD包。 在這裏安裝說明 。
安裝Perl GD
Perl GD 是一個autoloadable接口模塊 GD 。 這是一個流行的庫來建立和操縱 PNG 文件。 它是運行所需 Perl 腳本 graph-compare-results 在 MySQL基準套件 。 CentOS v6.3 DVD1安裝不來的 Perl GD 包中。 執行如下步驟來安裝 Perl GD 。 注意: 基於規則的執行安裝 iRULE4 。
♦ 若是你有一個互聯網鏈接
♦ 若是你沒有一個互聯網鏈接
若是你有一個互聯網鏈接 在終端,執行如下命令。
# yum install perl-GD
OPTIONS EXPLAINED install
Is used to install the latest version of a package or group of packages while ensuring that all dependencies are satisfied. (See Specifying package names for more information) If no package matches the given package name(s), they are assumed to be a shell glob and any matches are then installed. If the name starts with an @ character the rest of the name is used as though passed to the groupinstall command. If the name starts with a - character, then a search is done within the transaction and any matches are removed. If the name is a file, then install works like localinstall. If the name doesn’t match a package, then package "provides" are searched (Eg. "_sqlitecache.so()(64bit)") as are filelists (Eg. "/usr/bin/yum"). Also note that for filelists, wildcards will match multiple packages.
[root@localhost ~]# yum install perl-GD Loaded plugins: fastestmirror, langpacks base | 3.6 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 (1/4): extras/7/x86_64/primary_db | 54 kB 00:00 (2/4): base/7/x86_64/group_gz | 154 kB 00:00 (3/4): updates/7/x86_64/primary_db | 1.7 MB 00:01 (4/4): base/7/x86_64/primary_db | 5.1 MB 00:03 Loading mirror speeds from cached hostfile * base: mirrors.skyshe.cn * extras: mirrors.zju.edu.cn * updates: mirrors.pubyun.com Resolving Dependencies --> Running transaction check ---> Package perl-GD.x86_64 0:2.49-3.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: perl-GD x86_64 2.49-3.el7 base 173 k Transaction Summary ================================================================================ Install 1 Package Total download size: 173 k Installed size: 394 k Is this ok [y/d/N]: y Downloading packages: warning: /var/cache/yum/x86_64/7/base/packages/perl-GD-2.49-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for perl-GD-2.49-3.el7.x86_64.rpm is not installed perl-GD-2.49-3.el7.x86_64.rpm | 173 kB 00:00 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-1.1503.el7.centos.2.8.x86_64 (@anaconda) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : perl-GD-2.49-3.el7.x86_64 1/1 Verifying : perl-GD-2.49-3.el7.x86_64 1/1 Installed: perl-GD.x86_64 0:2.49-3.el7 Complete! [root@localhost ~]#
若是你沒有一個互聯網鏈接 找到一個系統,有一個互聯網鏈接。 下載 Perl GD 包的CentOS v6.3 http://vault.centos.org/6.3/os/i386/packages/perl - gd - 2.44 - 3. - el6.i686.rpm 。
下載RPM的大小爲180 KB。 在終端,改變控股RPM文件的目錄。 執行如下命令。
# rpm -ivh perl-GD-2.44-3.el6.i686.rpm
OPTIONS EXPLAINED
-i
This installs a new package.
-v
Print verbose information - normally routine progress messages will be displayed.
-h
Print 50 hash marks as the package archive is unpacked. Use with -v|--verbose for a nicer display.
2)添加一個MySQL用戶和組 運行 MySQL服務器 做爲根用戶是不安全的,因此不是明智的。 這是更好的運行 MySQL服務器 在一個有限的系統賬戶特權。 因此咱們將爲MySQL建立用戶和組。 在終端,執行如下命令。
# useradd -r -U mysql -M -d /usr/local/mysql/data
[root@localhost ~]# useradd -r -U mysql -M -d /usr/local/mysql/data [root@localhost ~]#
注意: 的主目錄 mysql 用戶將數據目錄 /usr/local/mysql/data/ 。 這是由於咱們計劃安裝MySQL服務器的目錄 /usr/local/mysql/ 。 您可使用一個不一樣的安裝目錄或數據存儲,若是你的願望。
OPTIONS EXPLAINED
-U
Create a group with the same name as the user and add the user to this group, in case USERGROUPS_ENAB in your /etc/login.defs is set to no. (By default this is set to yes).
-r
Create as system account -M Do not create the user´s home directory, in case CREATE_HOME in your /etc/login.defs is set to yes. (By default this is set to no). This is used because we do not want the files and directories contained in the skeleton directory to be copied to home directory. -d The new user will be created using HOME_DIR as the value for the user´s login directory. The default is to append the LOGIN name to BASE_DIR and use that as the login directory name. The directory HOME_DIR does not have to exist but will not be created if it is missing.
這將建立一個用戶和組,命名爲 mysql 。 他們將被建立爲系統帳戶和沒有密碼設置。主目錄將被設置爲 /usr/local/mysql/data/ 但它將不會建立。 The login shell will be /bin/bash 。
MySQL社區服務器下載源代碼 MySQL社區服務器的免費下載的版本 MySQL服務器 。 它能夠從MySQL開發區域。
讓咱們轉到 http://dev.mysql.com/downloads/ 。 的頁面,點擊 下載 選項卡上,將帶咱們去下載頁面清單不一樣MySQL項目。 下面 MySQL社區服務器 MySQL Community Server, 點擊 下載 連接,這將帶咱們到下載頁面。 咱們將會看到一個列表 通常可用(GA)版本 。 選擇平臺, 源代碼 。 滾動到,咱們將看到底部 通用Linux(架構獨立),壓縮的TAR存檔 Generic Linux (Architecture Independent), Compressed TAR Archive。 單擊 下載 按鈕時,它將帶咱們到一個頁面,咱們能夠用一個Oracle Web登陸/註冊帳戶。 若是你想要,你能夠。 但我選擇點擊 不,謝謝,就開始下載。 。 這將啓動下載
。 下載的文件 mysql-5.6.19.tar.gz 將 31.4 MB 在大小。
https://edelivery.oracle.com/EPD/Search/handle_go
Download | MySQL Cluster 7.4.6 TAR for Generic Linux (glibc2.5) x86 (64bit) | V75610-01 | 481M |
下載谷歌c++源代碼嘲笑框架 谷歌c++ Mocking框架(gmock)是一個圖書館使用c++編寫和模擬類。 MySQL服務器 使用它的 谷歌c++測試框架(gt) 基於單元測試。 若是你如今不下載這個,在配置過程當中會顯示如下錯誤。
Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
即便你啓用的選項 ENABLE_DOWNLOADS = 1 (即,假設你有一個活躍的網絡鏈接),配置腳本將給你如下錯誤。
CMake Error: Problem with tar_extract_all(): Invalid argument CMake Error: Problem extracting tar: /usr/src/mysql-5.6.19/source_downloads/gmock-1.6.0.zip
發生這種狀況是由於MySQL Bug 69854年 ,這將 固定在MySQL 5.7.4里程碑14 。 爲當前時間,咱們必須解決這個。
谷歌c++嘲笑框架能夠在Google代碼項目託管。 轉到 http://code.google.com/p/googlemock/ 。 的頁面,點擊 下載 選項卡上,將咱們的頁面下載清單。 版本的谷歌c++ Mocking框架,試圖下載的配置腳本 1.6.0 。 因此點擊 gmock-1.6.0.zip ,它將帶咱們去下載頁面。 點擊 gmock-1.6.0.zip 。 這將啓動下載。 下載的zip文件 gmock-1.6.0.zip 是 2.0 MB 在大小。
4)拆包和安裝 解包 確保你有複製下載的文件 mysql-5.6.19.tar.gz 和 gmock-1.6.0.zip 目錄 /usr/src/ 。 在終端,改變 /usr/src/ 目錄中。
# cd /usr/src
提取gzip壓縮文件包含 MySQL服務器 。
# tar -zxvf mysql-5.6.19.tar.gz
OPTIONS EXPLAINED
-x
extract files from an archive
-v
verbosely list files processed -z filter the archive through gzip -f use archive file or device ARCHIVE
將gmock zip文件解壓到指定的目錄
# unzip gmock-1.6.0.zip -d mysql-5.6.19/source_downloads
OPTIONS EXPLAINED
-d
An optional directory to which to extract files. By default, all files and subdirectories are recreated in the current directory; the -d option allows extraction in an arbitrary directory (always assuming one has permission to write to the directory). This option need not appear at the end of the command line; it is also accepted before the zipfile specification (with the normal options), immediately after the zipfile specification, or between the file(s) and the -x option. The option and directory may be concatenated without any white space between them, but note that this may cause normal shell behavior to be suppressed. In particular, ‘‘-d ~’’ (tilde) is expanded by Unix C shells into the name of the user’s home directory, but ‘‘-d~’’ is treated as a literal subdirectory ‘‘~’’ of the current directory.
這將建立一個目錄命名 source_downloads 在 mysql-5.6.19 目錄和提取特徵的zip文件。
安裝 注意: 基於規則的執行安裝 iRULE1 和 iRULE3 。 如今咱們將有一個目錄 mysql-5.6.19 提取的文件。 改變目錄的終端。
# cd mysql-5.6.19
cmake執行。 注意: • 默認的安裝目錄 /usr/local/mysql/ 。 若是你想要改變它,使用的選項 CMAKE_INSTALL_PREFIX 。 例子: # cmake。 -DCMAKE_INSTALL_PREFIX = your_custom_location • 默認的數據目錄 /usr/local/mysql/data/ 。 若是你想要改變它,使用的選項 MYSQL_DATADIR 。 例子: # cmake。 -DMYSQL_DATADIR = your_custom_location • 咱們安裝的默認配置選項,使用下面的命令 命令: # cmake。 韓 •配置選項的完整列表,參見如下連接 http://dev.mysql.com/doc/mysql-sourcebuild-excerpt/5.6/en/source-configuration-options.html
# cmake .
cmake會檢查咱們的系統所需的依賴項,分配值與系統相關的變量和使用這些值來生成Makefile。
執行。
# make
會看看咱們 Makefile 、編譯咱們的程序代碼並建立可執行文件描述的順序。
執行make install。
# make install
OPTIONS EXPLAINED
install
install will look for the target install in Makefile, and install MySQL Server to the specified location.
5)安裝過程 添加MySQL服務器可執行文件系統路徑 MySQL服務器 可執行文件位於 /usr/local/mysql/bin/ 和他們43號。 咱們不會爲每一個添加符號連接 /usr/bin/ 。 相反,咱們將添加 /usr/local/mysql/bin/ 到系統 路徑 變量。 路徑 是一個環境變量,它必須提供給全部用戶,在登陸和shell。 咱們必須添加一個腳本 /etc/profile.d/ 目錄中。 注意: • 閱讀的區別 環境變量 和 局部變量 。 • 閱讀的區別 登陸Shell 和 非登陸Shell 。
建立一個文件 mysql.sh 在 /etc/profile.d/ 目錄下面的內容。 這是 Bash shell 。
if ! echo ${PATH} | /bin/grep -q /usr/local/mysql/bin ; then PATH=/usr/local/mysql/bin:${PATH} fi
建立一個文件 mysql.csh 在 /etc/profile.d/ 目錄下面的內容。 這是給 C shell 和 Tenex C shell 。
if ( "${path}" !~ */usr/local/mysql/bin* ) then set path = ( /usr/local/mysql/bin $path ) endif
從這一刻起,任何新的登陸shell或shell催生了會 /usr/local/mysql/bin/ 在 路徑 變量。 但目前的外殼,咱們正在沒有它。 由於它是在腳本放在全球概要目錄。 因此咱們必須源對咱們工做shell腳本。 我使用 Bash shell 。 因此我在我目前的終端執行下面的命令。
# source /etc/profile.d/mysql.sh
將MySQL服務器庫添加到共享庫緩存 MySQL服務器 圖書館是位於 /usr/local/mysql/lib/ 。 但這些尚未共享。 其餘應用程序在運行時發現這些庫,動態連接器緩存在Linux中必須更新這些庫的信息。
建立一個文件 mysql.conf 在目錄中 /etc/ld.so.conf.d / 的條目 /usr/local/mysql/lib
# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig運行。
# ldconfig
ld.so.conf ldconfig掃描。 d文件夾並更新共享庫緩存,以便在運行時動態連接器能夠找到他們。
添加MySQL服務器MANPATH手冊 MySQL服務器 手冊是位於 /usr/local/mysql/man/ 。 咱們已經添加了 /usr/local/mysql/bin/ 到系統 路徑 變量。 因此男人工具會自動搜索的位置 /usr/local/mysql/man/ 手冊。 不須要額外的變化。
建立MySQL服務器受權表 在終端,改變 MySQL服務器 安裝目錄
# cd /usr/local/mysql
改變的全部者和組 /usr/local/mysql/ 目錄的內容 mysql 。 這樣作是爲了安裝 MySQL服務器 系統受權表。 咱們將恢復權限。
# chown -R mysql:mysql .
OPTIONS EXPLAINED
-R
operate on files and directories recursively
建立 MySQL服務器 受權表。 執行腳本 mysql_install_db 做爲 mysql 用戶。
# scripts/mysql_install_db --user=mysql
OPTIONS EXPLAINED
--user
The login username to use for running mysqld. Files and directories created by mysqld will be owned by this user. You must be root to use this option. By default mysqld runs using your current login name and files and directories that it creates will be owned by you.
改變後的全部者和組 /usr/local/mysql/ 根目錄的內容。
# chown -R root .
OPTIONS EXPLAINED
-R
operate on files and directories recursively
改變的主人 /usr/local/mysql/ 目錄 mysql 。
# chown -R mysql data
OPTIONS EXPLAINED
-R
operate on files and directories recursively
數據目錄已是集團將全部權 mysql 。 使用這個命令組和全部者 /usr/local/mysql/data/ 目錄將被設置爲 mysql 。
刪除權限 集團 和 別人 在 /usr/local/mysql/data/ 目錄中。 因此,只有 mysql 將能夠訪問它。
# chmod -R go-rwx data
OPTIONS EXPLAINED
-R
operate on files and directories recursively
go-rwx
Remove read,write & execute permissions for group & others
設置配置文件 默認的配置文件副本 my-default.cnf 成 /etc/ 目錄,重命名它 my.cnf 。
# cp support-files/my-default.cnf /etc/my.cnf
打開 MySQL服務器 配置文件 /etc/my.cnf 。 咱們必須進行某些更改成服務器正常工做。 注意:若是你已經改變了MySQL服務器安裝目錄或數據目錄的位置 MySQL的默認安裝目錄服務器 /usr/local/mysql/ 。 和MySQL服務器的默認數據目錄 /usr/local/mysql/data/ 。 若是你有改變其中任何一個,確保適當的更改的值 basedir 和 datadir 。
設置MySQL用戶 MySQL服務器 默認狀況下運行在用戶根。 運行 MySQL服務器 做爲根用戶是不安全的,因此不是明智的。 因此將 MySQL服務器 做爲標準的用戶運行 mysql 。 下方的 (mysqld) 部分添加一個新行,以下所示。
user = mysql
配置MySQL服務器的IP綁定 MySQL服務器 默認綁定到給定系統的全部接口上的全部IP地址。 若是咱們想要 MySQL服務器 只綁定在一個給定的IP地址,咱們必須配置以下。 下 (mysqld) 節中,添加如下的IP地址你想綁定。 注意: 取代 192.168.0.100 你的機器的IP地址。
bind-address = 192.168.0.100
這使得 MySQL服務器 192.168.0.100綁定到IP地址。 注意:若是咱們但願MySQL服務器綁定一組選定的接口,咱們能夠離開MySQL服務器的默認行爲,與防火牆咱們不想綁定的接口。
初始化MySQL服務器受權表。 執行mysqld_safe mysql用戶。
# mysqld_safe --user=mysql &
OPTIONS EXPLAINED
--user
Run the mysqld server as the user having the name user_name or the numeric user ID user_id. (「User」 in this context refers to a system login account, not a MySQL user listed in the grant tables.)
mysqld_safe 推薦的方式開始嗎 mysqld 服務器 UNIX 和 網絡 。 它初始化的mysql表包含特權授予決定容許用戶鏈接到服務器。 mysqld_safe 還增長了一些安全功能,如從新啓動服務器時發生錯誤和日誌記錄錯誤日誌文件運行時信息。 注意: 將 &命令,命令移動背景和給咱們的終端進行進一步的工做。 若是命令後吐出了標準輸出服務正在運行,只是新聞 ctrl - c 或關閉終端,打開一個新的。
設置MySQL服務器服務 複製 MySQL服務器 守護進程的啓動/中止腳本 mysql.server 來 /etc/rc.d/init.d/ 目錄,重命名它 mysql 。
# cp -v support-files/mysql.server /etc/rc.d/init.d/mysql
OPTIONS EXPLAINED
-v
explain what is being done
添加 mysql 做爲一個系統V init服務。
# chkconfig --add mysql
OPTIONS EXPLAINED
--add
This option adds a new service for management by chkconfig. When a new service is added, chkconfig ensures that the service has either a start or a kill entry in every runlevel. If any runlevel is missing such an entry, chkconfig creates the appropriate entry as specified by the default values in the init script. Note that default entries in LSB-delimited ’INIT INFO’ sections take precedence over the default runlevels in the initscript; if any Required-Start or Required-Stop entries are present, the start and stop priorities of the script will be adjusted to account for these dependencies.
這個選項增長了 mysql Sys V init服務管理 chkconfig 。 當添加一個新的服務, chkconfig 確保服務啓動或殺死進入每個級別。 若是任何運行級別缺失這樣一個條目, chkconfig 建立適當的條目中指定的默認值初始化腳本。 chkconfig 也爲咱們建立如下softlinks mysql 腳本對應的運行級別目錄。 /etc/rc.d/rc0.d/K36mysql /etc/rc.d/rc1.d/K36mysql /etc/rc.d/rc2.d/S64mysql /etc/rc.d/rc3.d/S64mysql /etc/rc.d/rc4.d/S64mysql /etc/rc.d/rc5.d/S64mysql /etc/rc.d/rc6.d/K36mysql
注意: K36mysql - K表明殺死。36意味着mysql將死於第36個訂單。 這是用於運行級0(關閉),1(單用戶模式),6(重啓)。 因此 mysql 服務將在運行級0、1和6。 S64mysql 64年代表明開始。意味着mysql將在64開始訂單。 這是用於GUI /自定義運行級二、三、四、5。 因此 mysql 服務將開始在運行級二、三、4和5。
最後,啓動 mysql 服務。
# service mysql start
OPTIONS EXPLAINED
start
starts the specified service
6)安裝缺乏的依賴關係 不過,有一件事未完成的- MySQL基準套件 。 MySQL服務器 附帶的 MySQL基準套件 ,這是安裝在 /usr/local/mysql/sql-bench/ 。 它能夠基準 MySQL服務器 和判斷給定實現執行好與壞。 都寫在基準腳本 Perl 並使用 DBI 模塊訪問數據庫服務器。 因此咱們須要如下運行 MySQL基準套件 - - - - - - Perl , DBI 和 DBD::mysql 。 上面的三個, Perl 和 DBI 除了安裝 DBD::mysql 。 咱們沒有安裝 DBD::mysql 在安裝以前 MySQL服務器 ,由於 DBD::mysql 須要 MySQL服務器 出現以前的安裝。 安裝 DBD::mysql ,按照 在這裏安裝說明 。 注意: 閱讀更多關於 DBI 和 libdbi 。
PID文件 語法: /usr/local/mysql/data/HOSTNAME.pid 例子: /usr/local/mysql/data/example.com.pid
套接字文件 / tmp / mysql.sock
服務文件 /etc/rc.d/init.d/mysql
缺省端口 3306年
可執行文件 列出並解釋了
配置文件 列出並解釋了
日誌文件 列出並解釋了
獲取服務器狀態信息 顯示MySQL服務的狀態
# service mysql status
顯示mysqld守護進程的狀態
# mysqladmin -u root -p ping
顯示服務器的狀態變量
# mysqladmin -u root -p status
顯示服務器的狀態變量和它們的值
# mysqladmin -u root -p extended-status
在活動服務器線程獲取信息 顯示活動服務器線程的列表
# mysqladmin -u root -p processlist
顯示充滿processlist活動服務器線程的列表
# mysqladmin -u root -p -v processlist
得到信息在服務器變量 顯示服務器系統變量和它們的值的列表
# mysqladmin -u root -p variables
獲取服務器版本信息
# mysqladmin -u root -p version