1. 運(yùn)行平臺(tái):CentOS 6.3 x86_64,基本等同于RHEL 6.3
2. 安裝方法:
安裝MySQL主要有兩種方法:一種是通過(guò)源碼自行編譯安裝,這種適合高級(jí)用戶(hù)定制MySQL的特性,這里不做說(shuō)明;另一種是通過(guò)編譯過(guò)的二進(jìn)制文件進(jìn)行安裝。二進(jìn)制文件安裝的方法又分為兩種:一種是不針對(duì)特定平臺(tái)的通用安裝方法,使用的二進(jìn)制文件是后綴為.tar.gz的壓縮文件;第二種是使用RPM或其他包進(jìn)行安裝,這種安裝進(jìn)程會(huì)自動(dòng)完成系統(tǒng)的相關(guān)配置,所以比較方便。
3. 下載安裝包:
a. 官方下載地址:
http://dev.mysql.com/downloads/mysql/#downloads
或鏡像文件下載:
http://dev.mysql.com/downloads/mirrors.html
2. 下載文件(根據(jù)操作系統(tǒng)選擇相應(yīng)的發(fā)布版本):
a. 通用安裝方法
mysql-5.5.29-linux2.6-x86_64.tar.gz
b. RPM安裝方法:
MySQL-server-5.5.29-2.el6.x86_64.rpm MySQL-client-5.5.29-2.el6.x86_64.rpm
4. 通用安裝步驟
a. 檢查是否已安裝,grep的-i選項(xiàng)表示匹配時(shí)忽略大小寫(xiě)
[root@localhost JavaEE]#rpm -qa|grep -i mysql mysql-libs-5.1.61-4.el6.x86_64 *可見(jiàn)已經(jīng)安裝了庫(kù)文件,應(yīng)該先卸載,不然會(huì)出現(xiàn)覆蓋錯(cuò)誤。注意卸:載時(shí)使用了--nodeps選項(xiàng),忽略了依賴(lài)關(guān)系: [root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps
b. 添加mysql組和mysql用戶(hù),用于設(shè)置mysql安裝目錄文件所有者和所屬組。
[root@localhost JavaEE]#groupadd mysql [root@localhost JavaEE]#useradd -r -g mysql mysql *useradd -r參數(shù)表示mysql用戶(hù)是系統(tǒng)用戶(hù),不可用于登錄系統(tǒng)。
c. 將二進(jìn)制文件解壓到指定的安裝目錄,我們這里指定為/usr/local
[root@localhost ~]# cd/usr/local/ [root@localhost local]#tar zxvf /path/to/mysql-5.5.29-linux2.6-x86_64.tar.gz *加壓后在/usr/local/生成了解壓后的文件夾mysql-5.5.29-linux2.6-x86_64,這名字太長(zhǎng),我們?yōu)樗⒁粋€(gè)符號(hào)鏈接mysql,方便輸入。 [root@localhost local]#ln -s mysql-5.5.29-linux2.6-x86_64 mysql
d. /usr/local/mysql/下的目錄結(jié)構(gòu)
Directory |
Contents of Directory |
bin |
Client programs and the mysqld server |
data |
Log files, databases |
docs |
Manual in Info format |
man |
Unix manual pages |
include |
Include (header) files |
lib |
Libraries |
scripts |
mysql_install_db |
share |
Miscellaneous support files, including error messages, sample configuration files, SQL for database installation |
sql-bench |
Benchmarks |
e. 進(jìn)入mysql文件夾,也就是mysql所在的目錄,并更改所屬的組和用戶(hù)。
[root@localhost local]#cd mysql [root@localhost mysql]#chown -R mysql . [root@localhost mysql]#chgrp -R mysql .
f. 執(zhí)行mysql_install_db腳本,對(duì)mysql中的data目錄進(jìn)行初始化并創(chuàng)建一些系統(tǒng)表格。注意mysql服務(wù)進(jìn)程mysqld運(yùn)行時(shí)會(huì)訪問(wèn)data目錄,所以必須由啟動(dòng)mysqld進(jìn)程的用戶(hù)(就是我們之前設(shè)置的mysql用戶(hù))執(zhí)行這個(gè)腳本,或者用root執(zhí)行,但是加上參數(shù)–user=mysql。
[root@localhost mysql]scripts/mysql_install_db --user=mysql *如果mysql的安裝目錄(解壓目錄)不是/usr/local/mysql,那么還必須指定目錄參數(shù),如 [root@localhost mysql]scripts/mysql_install_db --user=mysql --basedir=/opt/mysql/mysql --datadir=/opt/mysql/mysql/data*將mysql/目錄下除了data/目錄的所有文件,改回root用戶(hù)所有,mysql用戶(hù)只需作為mysql/data/目錄下所有文件的所有者。 [root@localhost mysql]chown -R root . [root@localhost mysql]chown -R mysql data
g. 復(fù)制配置文件
[root@localhost mysql] cp support-files/my-medium.cnf /etc/my.cnf
h. 將mysqld服務(wù)加入開(kāi)機(jī)自啟動(dòng)項(xiàng)。
*首先需要將scripts/mysql.server服務(wù)腳本復(fù)制到/etc/init.d/,并重命名為mysqld。 [root@localhostmysql] cp support-files/mysql.server /etc/init.d/ mysqld *通過(guò)chkconfig命令將mysqld服務(wù)加入到自啟動(dòng)服務(wù)項(xiàng)中。 [root@localhost mysql]#chkconfig --add mysqld *注意服務(wù)名稱(chēng)mysqld就是我們將mysql.server復(fù)制到/etc/init.d/時(shí)重命名的名稱(chēng)。 *查看是否添加成功 [root@localhost mysql]#chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off i. 重啟系統(tǒng),mysqld就會(huì)自動(dòng)啟動(dòng)了。 *檢查是否啟動(dòng) [root@localhost mysql]#netstat -anp|grep mysqld tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2365/mysqld unix 2 [ ACC ] STREAM LISTENING 14396 2365/mysqld /tmp/mysql.sock *如果不想重新啟動(dòng),那可以直接手動(dòng)啟動(dòng)。 [root@localhost mysql]#service mysqld start Starting MySQL.. SUCCESS! j. 運(yùn)行客戶(hù)端程序mysql,在mysql/bin目錄中,測(cè)試能否連接到mysqld。 [root@localhost mysql]#/usr/local/mysql/bin/mysql Welcome to the MySQLmonitor. Commands end with ; or g. Your MySQL connection idis 2 Server version:5.5.29-log MySQL Community Server (GPL) Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved. Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other names may betrademarks of their respective owners. Type 'help;' or 'h' forhelp. Type 'c' to clear the current input statement. mysql> quit Bye *此時(shí)會(huì)出現(xiàn)mysql>命令提示符,可以輸入sql語(yǔ)句,輸入quit或exit退出。為了避免每次都輸入mysql的全路徑/usr/local/mysql/bin/mysql,可將其加入環(huán)境變量中,在/etc/profile最后加入兩行命令: MYSQL_HOME=/usr/local/mysql export PATH=$PATH:$MYSQL_HOME/bin 這樣就可以在shell中直接輸入mysql命令來(lái)啟動(dòng)客戶(hù)端程序了 [root@localhost mysql]#mysql Welcome to the MySQLmonitor. Commands end with ; or g. Your MySQL connection idis 3 Server version:5.5.29-log MySQL Community Server (GPL) Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved. Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other namesmay be trademarks of their respective owners. Type 'help;' or 'h' forhelp. Type 'c' to clear the current input statement. mysql>
5. RPM安裝步驟
a. 檢查是否已安裝,grep的-i選項(xiàng)表示匹配時(shí)忽略大小寫(xiě)
[root@localhost JavaEE]#rpm -qa|grep -i mysql mysql-libs-5.1.61-4.el6.x86_64 可見(jiàn)已經(jīng)安裝了庫(kù)文件,應(yīng)該先卸載,不然會(huì)出現(xiàn)覆蓋錯(cuò)誤。注意卸載時(shí)使用了--nodeps選項(xiàng),忽略了依賴(lài)關(guān)系: [root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps
b. 安裝MySQL的服務(wù)器端軟件,注意切換到root用戶(hù):
[root@localhost JavaEE]#rpm -ivh MySQL-server-5.5.29-2.el6.x86_64.rpm 安裝完成后,安裝進(jìn)程會(huì)在Linux中添加一個(gè)mysql組,以及屬于mysql組的用戶(hù)mysql??赏ㄟ^(guò)id命令查看: [root@localhost JavaEE]#id mysql uid=496(mysql)gid=493(mysql) groups=493(mysql) MySQL服務(wù)器安裝之后雖然配置了相關(guān)文件,但并沒(méi)有自動(dòng)啟動(dòng)mysqld服務(wù),需自行啟動(dòng): [root@localhost JavaEE]#service mysql start Starting MySQL.. SUCCESS! 可通過(guò)檢查端口是否開(kāi)啟來(lái)查看MySQL是否正常啟動(dòng): [root@localhost JavaEE]#netstat -anp|grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 34693/mysqld
c. 安裝MySQL的客戶(hù)端軟件:
[root@localhost JavaEE]#rpm -ivh MySQL-client-5.5.29-2.el6.x86_64.rpm 如果安裝成功應(yīng)該可以運(yùn)行mysql命令,注意必須是mysqld服務(wù)以及開(kāi)啟: [root@localhost JavaEE]#mysql Welcome to the MySQLmonitor. Commands end with ; or g. Your MySQL connection idis 1 Server version: 5.5.29MySQL Community Server (GPL) Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademarkof Oracle Corporation and/or its affiliates. Other names may be trademarks oftheir respective owners. Type 'help;' or 'h' forhelp. Type 'c' to clear the current input statement. mysql>
d. RPM安裝方式文件分布
Directory |
Contents of Directory |
/usr/bin |
Client programs and scripts |
/usr/sbin |
The mysqld server |
/var/lib/mysql |
Log files, databases |
/usr/share/info |
Manual in Info format |
/usr/share/man |
Unix manual pages |
/usr/include/mysql |
Include (header) files |
/usr/lib/mysql |
Libraries |
/usr/share/mysql |
Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation |
/usr/share/sql-bench |
Benchmarks |
感謝大家的閱讀,希望大家受益良多。
本文轉(zhuǎn)自:https://blog.csdn.net/SuperChanon/article/details/8546254