您好,登錄后才能下訂單哦!
本篇內容主要講解“MySQL源碼安裝的方法介紹”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“MySQL源碼安裝的方法介紹”吧!
MYSQL的安裝分三種:命令行安裝、二進制安裝和源碼安裝
命令行安裝相對而言簡單,我們就不做過多陳述,今天就著重講講MYSQL的源碼安裝
編譯安裝過程描述:
1.下載源代碼
2.檢查源碼編譯所需的依賴包是否齊全
3.解壓編譯
4.make && make install
5.初始化數據目錄
6.數據庫權限設置
7.定義啟動方式
軟件安裝的常規約定:
軟件安裝包放在/usr/local/src下
軟件根目錄basedir在/usr/local/xxx下,如:/usr/local/mysql
配置文件在/etc/下,如:/etc/my.cnf
數據目錄datadir一般放在單獨的磁盤上
mysql服務名為mysqld
========
準備
========
#創建數據目錄
[root@xxx ~]# mkdir /data/mysql
#創建根目錄
[root@xxx ~]# mkdir /usr/local/mysqlrp
#進入軟件存放目錄
[root@xxx ~]# cd /usr/local/src/
[root@xxx src]# mv /root/mysql-5.6.24.tar.gz .
[root@xxx src]# tar -zxvf mysql-5.6.24.tar.gz
[root@xxx src]# cd mysql-5.6.24
#檢查cmake是否安裝,如果未安裝,請使用yum install cmake或其它方式安裝
[root@xxx mysql-5.6.24]# which cmake
/usr/bin/cmake
#安裝必備的依賴包
[root@xxx mysql-5.6.24]# yum install ncurses-devel
[root@xxx mysql-5.6.24]# yum install bison
#=======
編譯
#=======
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysqlrp \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
[root@xxx mysql-5.6.24]# ls /usr/local/mysqlrp/
[root@xxx mysql-5.6.24]#
[root@xxx mysql-5.6.24]# ls /data/mysql/
[root@xxx mysql-5.6.24]#
[root@xxx mysql-5.6.24]# make
[root@xxx mysql-5.6.24]# ls /usr/local/mysqlrp/
[root@xxx mysql-5.6.24]# ls /data/mysql/
[root@xxx mysql-5.6.24]#
#make install時才會在根目錄下生成文件
[root@xxx mysql-5.6.24]# make install
[root@xxx mysql-5.6.24]# ls /usr/local/mysqlrp/
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[root@xxx mysql-5.6.24]# ls /data/mysql/
[root@xxx mysql-5.6.24]#
[root@xxx mysql-5.6.24]# cd /usr/local/mysqlrp/
#創建mysql管理用戶及組
[root@xxx mysqlrp]# groupadd mysql
[root@xxx mysqlrp]# useradd mysql -g mysql
#修改配置文件,修改根目錄、數據目錄位置。
[root@xxx local]# vi /etc/my.cnf
...
[mysqld]
basedir=/usr/local/mysqlrp
datadir=/data/mysql
#初始化數據目錄
[root@xxx mysqlrp]# ./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf &
#制作mysql服務mysqld
[root@xxx mysqlrp]# cp support-files/mysql.server /etc/init.d/mysqld
#修改各個目錄對應權限
[root@xxx mysqlrp]#chown -R mysql.mysql /usr/local/mysqlrp
[root@xxx mysqlrp]#chown -R mysql.mysql /data/mysql
[root@xxx mysqlrp]#chown mysql.mysql /etc/my.cnf
[root@xxx mysqlrp]#chown mysql.mysql /etc/init.d/mysqld
[root@xxx mysqlrp]#chmod -R 755 /usr/local/mysqlrp
[root@xxx mysqlrp]#chmod -R 755 /data/mysql
root@xxx mysqlrp]#chmod 644 /etc/my.cnf
[root@xxx mysqlrp]#chmod 755 /etc/init.d/mysqld
#啟動mysql服務
[root@xxx local]# service mysqld start
Starting MySQL.
[ OK ]
#=======
#源碼編譯常見依賴包
#=======
kernel-headers-2.6.32-358.el6.x86_64.rpm
glibc-headers-2.12-1.107.el6.x86_64.rpm
glibc-devel-2.12-1.107.el6.x86_64.rpm
cpp-4.4.7-3.el6.x86_64.rpm
gcc-4.4.7-3.el6.x86_64.rpm
libstdc++-devel-4.4.7-3.el6.x86_64.rpm
gcc-c++-4.4.7-3.el6.x86_64.rpm
autoconf-2.63-5.1.el6.noarch.rpm
automake-1.11.1-4.el6.noarch.rpm
zlib-1.2.3-29.el6.x86_64.rpm
ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
libgcrypt-1.4.5-9.el6_2.2.x86_64.rpm
libtool-2.2.6-15.5.el6.x86_64.rpm
bison-2.4.1-5.el6.x86_64.rpm
#=======
#附實驗2則,解釋常見疑問
#實驗1說明,數據目錄初始化的時候,必須在根目錄basedir下初始化目錄(具體數據目錄可以自定義),使用初始化腳本進行初始化。
#實驗2說明,數據庫在編譯的時候會修改源碼里面的內容,例如src/mysql-5.6.24/support-files/mysql.server ,會將根目錄修改為編譯時指定的根目錄
# 數據庫編譯時指定數據目錄,安裝完成后mysql工具沒有指定數據目錄且根目錄下沒有data目錄會優先將編譯時指定的數據目錄作為自己的數據目錄
#=======
點擊(此處)折疊或打開
#=======
#實驗1
#=======
[root@xxx mysqlrp]# mkdir /tmp/test
#=======
#測試進入臨時目錄,做數據目錄初始化
#=======
[root@xxx mysqlrp]# cd /tmp/test/
[root@xxx test]# /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql &
[1] 36700
[root@xxx test]# FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
[1]+ Exit 1 /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql
[root@xxx test]# /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql --datadir=/data/mysql &
[1] 36704
[root@xxx test]# FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
opy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
[1]+ Exit 1 /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql --datadir=/data/mysql
[root@xxx test]# /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysqlrp --datadir=/data/mysql &
#=======
#指定了根目錄后總算初始化成功
#=======
[root@xxx mysqlrp]# cp support-files/mysql.server /etc/init.d/mysqld
[root@xxx mysqlrp]# chown -R mysql.mysql /usr/local/mysql
[root@xxx mysqlrp]# chown -R mysql.mysql /data/mysql/
[root@xxx mysqlrp]# mkdir log
[root@xxx mysqlrp]# chown -R mysql.mysql log
[root@xxx mysqlrp]# ./bin/mysqld_safe --user=mysql &
[1] 37694
[root@xxx mysqlrp]# 151113 15:45:58 mysqld_safe Logging to '/data/mysql/zc-appname-ip-ip.err'.
151113 15:45:59 mysqld_safe Starting mysqld daemon with databases from /data/mysql
151113 15:45:59 mysqld_safe mysqld from pid file /data/mysql/zc-appname-ip-ip.pid ended
[1]+ Done ./bin/mysqld_safe --user=mysql
[root@xxx mysqlrp]# ps -ef|grep mysql
root 37847 12729 0 15:46 pts/3 00:00:00 grep mysql
#=======
#試圖啟動,失敗
#=======
[root@xxx local]# mv mysqlrp/ mysql
[root@xxx mysqlrp]# chown -R mysql.mysql /usr/local/mysql
[root@xxx local]# mv mysql/ mysqlrp
[root@xxx local]# service mysqld start
Starting MySQL.The server quit without updating PID file (/data/mysql/zc-appname-ip-ip.pid). [FAILED]
#=======
#試圖啟動,失敗
#=======
[root@xxx local]# cd mysqlrp/
[root@xxx mysqlrp]# ./bin/mysqld
mysqld mysqld_multi mysqld_safe mysqldump mysqldumpslow
[root@xxx mysqlrp]# ./bin/mysqld_safe --user=mysql&
[1] 38052
[root@xxx mysqlrp]# 151113 15:49:31 mysqld_safe Logging to '/data/mysql/zc-appname-ip-ip.err'.
151113 15:49:31 mysqld_safe Starting mysqld daemon with databases from /data/mysql
151113 15:49:32 mysqld_safe mysqld from pid file /data/mysql/zc-appname-ip-ip.pid ended
[1]+ Done ./bin/mysqld_safe --user=mysql
[root@xxx mysqlrp]# ps -ef|grep mysql
root 38205 12729 0 15:49 pts/3 00:00:00 grep mysql
#=======
#試圖啟動,失敗
#=======
[root@xxx mysqlrp]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ &
#=======
#初始化數據目錄成功
#=======
[root@xxx mysqlrp]# ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysqlrp/data/ &
#=======
#再次初始化數據目錄,成功
#=======
[root@xxx mysqlrp]# ./bin/mysqld_safe --user=mysql &
[1] 38312
[root@xxx mysqlrp]# 151113 15:56:03 mysqld_safe Logging to '/usr/local/mysqlrp/data/zc-appname-ip-ip.err'.
151113 15:56:03 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysqlrp/data
[root@xxx mysqlrp]# ps -ef|grep mysql
root 38312 12729 0 15:56 pts/3 00:00:00 /bin/sh ./bin/mysqld_safe --user=mysql
mysql 38441 38312 3 15:56 pts/3 00:00:00 /usr/local/mysqlrp/bin/mysqld --basedir=/usr/local/mysqlrp --datadir=/usr/local/mysqlrp/data --plugin-dir=/usr/local/mysqlrp/lib/plugin --user=mysql --log-error=/usr/local/mysqlrp/data/zc-appname-ip-ip.err --pid-file=/usr/local/mysqlrp/data/zc-appname-ip-ip.pid --socket=/tmp/mysql.sock
root 38465 12729 0 15:56 pts/3 00:00:00 grep mysql
#=======
#試圖啟動,成功
#=======
#=======
#實驗2
#=======
[root@xxx mysqlrp]# 151113 15:56:43 mysqld_safe mysqld from pid file /usr/local/mysqlrp/data/zc-appname-ip-ip.pid ended
ps
PID TTY TIME CMD
12729 pts/3 00:00:00 bash
38471 pts/3 00:00:00 ps
[1]+ Done ./bin/mysqld_safe --user=mysql
[root@xxx mysqlrp]# ps -ef|grep mysql
root 38473 12729 0 15:56 pts/3 00:00:00 grep mysql
[root@xxx mysqlrp]# service mysqld start
Starting MySQL.The server quit without updating PID file (/[FAILED]ql/zc-appname-ip-ip.pid).
[root@xxx mysqlrp]#
[root@xxx local]# cp src/mysql-5.6.24/support-files/mysql.server /etc/init.d/mysqldcp: overwrite `/etc/init.d/mysqld'? y
[root@xxx local]# service mysqld start
/etc/init.d/mysqld: line 256: my_print_defaults: command not found
/etc/init.d/mysqld: line 276: cd: /usr/local/mysqlrp: No such file or directory
Starting MySQLCouldn't find MySQL server (/usr/local/mysqlr[FAILED]sqld_safe)
[root@xxx local]# mv mysql mysqlrp
[root@xxx local]# service mysqld start
Starting MySQL.The server quit without updating PID file (/[FAILED]ql/zc-appname-ip-ip.pid).
[root@xxx local]# vi /etc/my.cnf
datadir=xxxx
[root@xxx local]# service mysqld start
Starting MySQL.
[ OK ]
到此,相信大家對“MySQL源碼安裝的方法介紹”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。