0. summary
1. MySQL官方網(wǎng)站介紹
. 1.1 Developer Zone - MySQL工程師版塊
. 1.2 Downloads - MySQL下載
. 1.3 Documentation - MySQL文檔
2. MySQL下載
3. MySQL安裝
. 3.1 安裝5.6.31
. 3.2 mysqld_safe
. 3.3 mysqld
. 3.4 mysql.server
. 3.4.1 mysql.server stop的實(shí)質(zhì)
1. MySQL官方網(wǎng)站介紹
1.1 Developer Zone - MySQL工程師版塊
- Articles - Oracle MySQL工程師博客漠秋,包含一些新功能的介紹
- Forums - 論壇
- Planet MySQL - 和MySQL相關(guān)從業(yè)人員的博客
- Bugs - MySQL BugList
- Worklog - 開發(fā)記錄
- Labs - MySQL實(shí)驗(yàn)特性刃唤,還沒(méi)有穩(wěn)定版本戈盈,會(huì)慢慢上線
1.2 Downloads - MySQL下載
- MySQL Enterprise Edition - MySQL企業(yè)版本
- MySQL Cluster CGE - 獨(dú)立的一套產(chǎn)品益眉,使用的是NDB Cluster存儲(chǔ)引擎液肌,與其他兩個(gè)產(chǎn)品沒(méi)有關(guān)系关摇。
- MySQL Community Edition - 社區(qū)版
- MySQL Community Server - MySQL Server
- MySQL Cluster - MySQL Cluster社區(qū)版本
- MySQL Fabric - MySQL中間件
- MySQL Router - 路由荠卷,可以結(jié)合Fabric一起使用幻林。暫時(shí)不支持分庫(kù)分表终吼。
- MySQL Utilities - MySQL應(yīng)用程序包
- MySQL Workbench - 圖型化客戶端镀赌,跨平臺(tái)〖使颍可以綁定MySQL Utilities
- MySQL Connectors - 驅(qū)動(dòng)
1.3 Documentation - MySQL文檔
推薦下載epub版本商佛,適合手機(jī)喉钢、移動(dòng)設(shè)備
MySQL-5.7 EPUB版本下載地址:
MORE(有一些有用的示例數(shù)據(jù)庫(kù),比如employee data)
2. MySQL下載
- Source Code - 主要作用是為了讓開發(fā)人員研究源碼以及crash時(shí)候可以定位到哪個(gè)文件的哪一行良姆。自己編譯對(duì)性能提升不明顯肠虽,一般都c make完了之后再make. intel c++編譯可能有提升,但是編譯器是收費(fèi)的玛追。
- Linux-Generic - 推薦下載的版本税课,其他系統(tǒng)版本安裝路徑都是根據(jù)自己發(fā)行版本,并且RPM包不容易一臺(tái)機(jī)器安裝多個(gè)MySQL版本痊剖。
下載地址:
http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
不推薦使用5.5的版本韩玩,bug大多在5.6才修復(fù)。
下載完注意check md5值邢笙。如下:
root@codelab:~/soft# md5sum mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
61137ce6387be7abf6571abe3f6cdcd0 mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
3. MySQL安裝
MySQL的安裝比較簡(jiǎn)單啸如,將安裝包解壓后打開INSTALL_BINARY文件,按照shell>開頭的步驟進(jìn)行操作氮惯。
3.1 安裝5.6.31
5.6.31的解壓包里沒(méi)有包含INSTALL_BINARY, 可以拿MySQL-5.6.27為例叮雳,如下:
shell> yum search libaio # search for info
shell> yum install libaio # install library
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
安裝過(guò)程如下:
[root@lab11g ~]# rpm -qa | grep libaio ---- 異步IO的庫(kù)
libaio-0.3.106-5
libaio-0.3.106-5
libaio-devel-0.3.106-5
libaio-devel-0.3.106-5
[root@lab11g ~]# groupadd mysql
[root@lab11g ~]# useradd -r -g mysql mysql
[root@lab11g ~]# cd /usr/local
[root@lab11g local]# tar zxf /install/mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
[root@lab11g local]# ln -s /usr/local/mysql-5.6.31-linux-glibc2.5-x86_64 mysql ---- 創(chuàng)建mysql的快捷鏈接,取消是unlink
[root@lab11g local]# cd mysql
[root@lab11g mysql]# chown -R mysql .
[root@lab11g mysql]# chgrp -R mysql .
[root@lab11g mysql]# scripts/mysql_install_db --user=mysql ---- 初始化mysql數(shù)據(jù)庫(kù)
Installing MySQL system tables...2016-06-25 15:49:58 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --
......
[root@lab11g mysql]# chown -R root .
[root@lab11g mysql]# chown -R mysql data
[root@lab11g mysql]# bin/mysqld_safe --user=mysql & ---- 通過(guò)mysql用戶來(lái)啟動(dòng)進(jìn)程到后臺(tái)
[1] 7306
......
[root@lab11g mysql]# cp support-files/mysql.server /etc/init.d/mysql.server ---- 可選步驟
初始化mysql數(shù)據(jù)庫(kù)那步驟之后可以發(fā)現(xiàn)data下面多了一些文件妇汗,原來(lái)是空的帘不,如下:
[root@lab11g mysql]# ll data
總計(jì) 110736
-rw-rw---- 1 mysql mysql 56 06-25 15:50 auto.cnf
-rw-rw---- 1 mysql mysql 12582912 06-25 15:50 ibdata1
-rw-rw---- 1 mysql mysql 50331648 06-25 15:50 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 06-25 15:49 ib_logfile1
-rw-r----- 1 mysql root 2146 06-25 15:50 lab11g.err ---- 默認(rèn)是hostname.err
-rw-rw---- 1 mysql mysql 5 06-25 15:50 lab11g.pid
drwx------ 2 mysql mysql 4096 06-25 15:49 mysql
drwx------ 2 mysql mysql 4096 06-25 15:49 performance_schema
drwxr-xr-x 2 mysql mysql 4096 06-25 15:49 test
#### lab11g.err ####
160625 15:50:22 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2016-06-25 15:50:23 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for
more details).
2016-06-25 15:50:23 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.31) starting as process 7396 ...
2016-06-25 15:50:23 7396 [Note] Plugin 'FEDERATED' is disabled.
2016-06-25 15:50:23 7396 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-06-25 15:50:23 7396 [Note] InnoDB: The InnoDB memory heap is disabled
2016-06-25 15:50:23 7396 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-06-25 15:50:23 7396 [Note] InnoDB: Memory barrier is not used
......
如果有錯(cuò)誤的話會(huì)有Error的信息。
另外還有種可能杨箭,操作系統(tǒng)已經(jīng)安裝了部分包寞焙,存在my.cnf配置文件,比如:
/etc/my.cnf ---- rhel
/etc/mysql/my.cnf ---- debain
初始化時(shí)候會(huì)以配置文件里面的信息去啟動(dòng)互婿,比如:
datadir = /data/mysql_data
如果沒(méi)有權(quán)限捣郊,初始化就會(huì)失敗。該目錄權(quán)限應(yīng)該是mysql:mysql.
3.2 mysqld_safe
mysqld_safe是mysqld的守護(hù)進(jìn)程慈参,只要mysqld_safe存在呛牲,mysqld終止后會(huì)自動(dòng)去重啟。如下:
[root@lab11g mysql]# ps -ef | grep mysqld
root 7306 5918 0 15:50 pts/2 00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql 7396 7306 0 15:50 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-
dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/lab11g.err --pid-file=/usr/local/mysql/data/lab11g.pid
root 7645 5918 0 16:01 pts/2 00:00:00 grep mysqld
[root@lab11g mysql]# kill -9 7396
[root@lab11g mysql]# bin/mysqld_safe: line 166: 7396 已殺死 nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --
datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/lab11g.err --pid-
file=/usr/local/mysql/data/lab11g.pid < /dev/null >> /usr/local/mysql/data/lab11g.err 2>&1
160625 16:01:35 mysqld_safe Number of processes running now: 0
160625 16:01:35 mysqld_safe mysqld restarted
[root@lab11g mysql]# ps -ef | grep mysqld
root 7306 5918 0 15:50 pts/2 00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql 7662 7306 17 16:01 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-
dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/lab11g.err --pid-file=/usr/local/mysql/data/lab11g.pid
root 7688 5918 0 16:01 pts/2 00:00:00 grep mysqld
3.3 mysqld
我們也可以使用mysqld去啟動(dòng)驮配,如下:
[root@lab11g mysql]# mysqladmin shutdown
[root@lab11g mysql]# bin/mysqld --user=mysql &
[1] 7772
......
通過(guò)mysqld啟動(dòng)娘扩,異常后無(wú)法自動(dòng)重啟,如下:
[root@lab11g mysql]# ps -ef | grep mysqld
mysql 7772 5918 3 16:02 pts/2 00:00:00 bin/mysqld --user=mysql
root 7803 5918 0 16:03 pts/2 00:00:00 grep mysqld
[root@lab11g mysql]# kill -9 7772
......
[1]+ 已殺死 bin/mysqld --user=mysql
[root@lab11g mysql]# ps -ef | grep mysqld
root 8032 5918 0 16:14 pts/2 00:00:00 grep mysqld
安裝mysql其實(shí)就是個(gè)初始化以及啟動(dòng)進(jìn)程和實(shí)例壮锻,安裝實(shí)際上不叫安裝琐旁,mysql就是個(gè)二進(jìn)制程序,如下:
[root@lab11g bin]# file mysqld
mysqld: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), not stripped
另外還有個(gè)debug的版本猜绣,可以通過(guò)gdb一些這樣的命令來(lái)進(jìn)行調(diào)試灰殴,并打印出內(nèi)部的信息。
[root@lab11g bin]# file mysqld-debug
mysqld-debug: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), not stripped
3.4 mysql.server
執(zhí)行了cp support-files/mysql.server /etc/init.d/mysql.server, 可以通過(guò)mysql.server來(lái)啟停
[root@lab11g mysql]# ps -ef | grep mysqld
root 15400 5918 0 22:24 pts/2 00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql 15490 15400 13 22:24 pts/2 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-
dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/lab11g.err --pid-file=/usr/local/mysql/data/lab11g.pid
root 15523 5918 0 22:24 pts/2 00:00:00 grep mysqld
[root@lab11g mysql]# /etc/init.d/mysql.server stop
Shutting down MySQL..160625 22:24:58 mysqld_safe mysqld from pid file /usr/local/mysql/data/lab11g.pid ended
......
[root@lab11g mysql]# ps -ef | grep mysqld
root 15546 5918 0 22:25 pts/2 00:00:00 grep mysqld
還可以加到開機(jī)啟動(dòng)掰邢,如下:
[root@lab11g mysql]# chkconfig --add mysql.server
[root@lab11g mysql]# chkconfig --list | grep mysql
mysql.server 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
debain下如果不添加systemctl管理验懊,直接/etc/init.d/mysql.server無(wú)法啟動(dòng)
root@codelab:/usr/local/mysql# /etc/init.d/mysql.server start
[....] Starting mysql.server (via systemctl): mysql.server.serviceFailed to start mysql.server.service: Unit mysql.server.service failed to load: No such file or
directory.
failed!
debain下添加systemctl管理方法
systemctl load mysql.server ---- chkconfig --add mysql.server
systemctl enable mysql.server ---- chkconfig mysql.server on
systemctl list-units --type=service ---- chkconfig --list顯示所有已經(jīng)啟動(dòng)的服務(wù)
3.4.1 mysql.server stop的實(shí)質(zhì)
調(diào)用的kill, 所以和mysqladmin不一樣擅羞,不需要密碼,如下:
'stop')
# Stop daemon. We use a signal here to avoid having to know the
# root password.
if test -s "$mysqld_pid_file_path"
then
mysqld_pid=`cat "$mysqld_pid_file_path"`
if (kill -0 $mysqld_pid 2>/dev/null)
then
echo $echo_n "Shutting down MySQL"
kill $mysqld_pid
# mysqld should remove the pid file when it exits, so wait for it.
wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?
else
log_failure_msg "MySQL server process #$mysqld_pid is not running!"
rm "$mysqld_pid_file_path"
fi
# Delete lock for RedHat / SuSE
if test -f "$lock_file_path"
then
rm -f "$lock_file_path"
fi
exit $return_value
else
log_failure_msg "MySQL server PID file could not be found!"
fi
;;
[root@lab11g mysql_data]# ll *pid
-rw-r----- 1 mysql mysql 5 07-12 20:33 lab11g.pid
-rw-rw---- 1 root root 5 07-12 20:33 mysqld_safe.pid
[root@lab11g mysql_data]# cat lab11g.pid
6129
[root@lab11g mysql_data]# pidof mysqld
9220 9166 9147 6129
[root@lab11g mysql_data]# kill 6129 -- 發(fā)送一個(gè)特定的信號(hào)給當(dāng)前的進(jìn)程义图,MySQL捕獲信號(hào)進(jìn)行處理减俏,和mysqladmin shutdown一樣的處理過(guò)程