一、MySQL介紹
MySQL是一個(gè)關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),由瑞典MySQL AB 公司開(kāi)發(fā),目前屬于 Oracle 旗下公司。MySQL 最流行的關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),在 WEB 應(yīng)用方面MySQL是最好的 RDBMS (Relational Database Management System,關(guān)系數(shù)據(jù)庫(kù)管理系統(tǒng)) 應(yīng)用軟件之一。
MySQL是一種關(guān)聯(lián)數(shù)據(jù)庫(kù)管理系統(tǒng),關(guān)聯(lián)數(shù)據(jù)庫(kù)將數(shù)據(jù)保存在不同的表中,而不是將所有數(shù)據(jù)放在一個(gè)大倉(cāng)庫(kù)內(nèi),這樣就增加了速度并提高了靈活性。
MySQL所使用的 SQL 語(yǔ)言是用于訪問(wèn)數(shù)據(jù)庫(kù)的最常用標(biāo)準(zhǔn)化語(yǔ)言。MySQL 軟件采用了雙授權(quán)政策,它分為社區(qū)版和商業(yè)版,由于其體積小、速度快、總體擁有成本低,尤其是開(kāi)放源碼這一特點(diǎn),一般中小型網(wǎng)站的開(kāi)發(fā)都選擇 MySQL 作為網(wǎng)站數(shù)據(jù)庫(kù)。
二、MySQL的版本選擇
技巧1.選擇版本GA版本,Development版本、Alpha版本和Beta版本一般不用在項(xiàng)目中。因?yàn)樗鼈兛隙ù嬖谥卮蟮膯?wèn)題或某些功能未完全實(shí)現(xiàn)。
技巧2.選擇GA版本,不要選擇最新,一般選擇前3-4個(gè)版本或10個(gè)月前的版本。
技巧3.查看官方說(shuō)明,沒(méi)有重大bug更新的版本
三、安裝介紹
MySQL從5.3開(kāi)始使用cmake的安裝方式。
本次版本選擇用戶(hù)量最多的MySQL5.5系列,分別給出本次需要的5.5.52和最新版的下載地址
MySQL5.5系下載地址
http://dev.mysql.com/downloads/mysql/5.5.html#downloads
四、安裝前準(zhǔn)備
當(dāng)前系統(tǒng)
成都創(chuàng)新互聯(lián)專(zhuān)注于大悟網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供大悟營(yíng)銷(xiāo)型網(wǎng)站建設(shè),大悟網(wǎng)站制作、大悟網(wǎng)頁(yè)設(shè)計(jì)、大悟網(wǎng)站官網(wǎng)定制、成都微信小程序服務(wù),打造大悟網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供大悟網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。
[root@db01 ~]# cat /etc/redhat-release CentOS release 6.8 (Final) [root@db01 ~]# uname -r 2.6.32-642.el6.x86_64 [root@db01 ~]# uname -m x86_64 [root@db01 ~]# uname -n db01
1、上傳所需要的MySQL編譯安裝包
可以使用rz,ftp等工具上傳至指定目錄;
演示: 我的存放/server/tools目錄下
[root@db01 ~]# mkdir -p /server/tools [root@db01 ~]# cd /server/tools [root@db01 tools]# rz rz waiting to receive. Starting zmodem transfer. Press Ctrl+C to cancel. Transferring mysql-5.5.52.tar.gz... 100% 20539 KB 20539 KB/sec 00:00:01 0 Errors [root@db01 tools]# [root@db01 tools]# ll 總用量 20540 -rw-r--r-- 1 root root 21032776 8月 26 17:32 mysql-5.5.52.tar.gz
2、安裝cmake工具
MySQL從5.3開(kāi)始使用cmake工具安裝
cmake工具地址https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz
演示:
1)下載工具
[root@db01 tools]# pwd /server/tools [root@db01 tools]# wget https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz [root@db01 tools]# ls -l cmake-3.5.2.tar.gz -rw-r--r-- 1 root root 6863498 4月 16 01:40 cmake-3.5.2.tar.gz
2)解壓cmake3.5.2
[root@db01 tools]# tar xf cmake-3.5.2.tar.gz [root@db01 tools]# ls -ld cmake-3.5.2 drwxr-xr-x 11 root root 4096 4月 27 09:45 cmake-3.5.2
3)安裝cmake3.5.2
[root@db01 tools]# cd cmake-3.5.2 [root@db01 cmake-3.5.2]# ./configure [root@db01 cmake-3.5.2]# gmake [root@db01 cmake-3.5.2]# gmake install [root@db01 cmake-3.5.2]# cd ../
PS:如果嫌棄麻煩那么 yum安裝也可以(yum install -y cmake)
[root@db01 tools]# yum install -y cmake
3、安裝ncurses-devel依賴(lài)
ncurses,計(jì)算機(jī)語(yǔ)言,指的是提供字符終端處理庫(kù)。
[root@db01 tools]# yum install -y ncurses-devel
4、安裝MySQL
1)創(chuàng)建用戶(hù)和組
[root@db01 tools]# useradd -Ms /sbin/nologin mysql [root@db01 tools]# id mysql uid=501(mysql) gid=501(mysql) 組=501(mysql)
2)解壓編譯安裝
[root@db01 tools]# tar xf mysql-5.5.52.tar.gz [root@db01 tools]# cd mysql-5.5.52 [root@db01 mysql-5.5.52]# cmake . \ -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.52 \ -DMYSQL_DATADIR=/application/mysql-5.5.52/data \ -DMYSQL_UNIX_ADDR=/application/mysql-5.5.52/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \ -DENABLED_LOCAL_INFILE=ON \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \ -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \ -DWITH_FAST_MUTEXES=1 \ -DWITH_ZLIB=bundled \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_READLINE=1 \ -DWITH_EMBEDDED_SERVER=1 \ -DWITH_DEBUG=0 ………………………省略…………………………… oaded-virtual -Wno-unused-parameter -- CMAKE_C_FLAGS_RELWITHDEBINFO: -O2 -g -DNDEBUG -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1 -- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O2 -g -DNDEBUG -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1 -- Configuring done -- Generating done -- Build files have been written to: /server/tools/mysql-5.5.52 [root@db01 mysql-5.5.52]# echo $? 0
<==顯示如上結(jié)果配置成功
參數(shù)解釋解釋?zhuān)?/p>
cmake . \ -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.52 \ #指定安裝目錄 -DMYSQL_DATADIR=/application/mysql-5.5.52/data \ #指定數(shù)據(jù)存放目錄(重要) -DMYSQL_UNIX_ADDR=/application/mysql-5.5.52/tmp/mysql.sock \ #指定sock的路徑 -DDEFAULT_CHARSET=utf8 \ #指定默認(rèn)字符集 -DDEFAULT_COLLATION=utf8_general_ci \ #指定校準(zhǔn)字符集編碼 -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \ #安裝所需字符集 -DENABLED_LOCAL_INFILE=ON \ #啟用加載本地?cái)?shù)據(jù) -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #支持innode儲(chǔ)存引擎 -DWITH_FEDERATED_STORAGE_ENGINE=1 \ #支持federated引擎 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ #支持黑洞儲(chǔ)存引擎 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \ -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \ #安裝支持?jǐn)?shù)據(jù)庫(kù)分區(qū) -DWITH_FAST_MUTEXES=1 \ -DWITH_ZLIB=bundled \ #zlib壓縮模式 -DENABLED_LOCAL_INFILE=1 \ -DWITH_READLINE=1 \ -DWITH_EMBEDDED_SERVER=1 \ -DWITH_DEBUG=0 #禁用debug,開(kāi)啟影響性能
提示,編譯時(shí)可配置的選項(xiàng)很多,具體可參考結(jié)尾官方文檔
3)編譯安裝
[root@db01 mysql-5.5.52]# make ………………………省略…………………………… [100%] Built target my_safe_process [root@db01 mysql-5.5.52]# echo $? 0 <==編譯成功 [root@db01 mysql-5.5.52]# make install ………………………省略…………………………… -- Installing: /application/mysql-5.5.52/man/man1/mysqlslap.1 -- Installing: /application/mysql-5.5.52/man/man8/mysqld.8 [root@db01 mysql-5.5.52]# echo $? 0 <==安裝成功
如果上述操作未出現(xiàn)錯(cuò)誤,則MySQL5.5.52軟件cmake方式的安裝就算成功了
4)創(chuàng)建軟連接,去除版本號(hào)
[root@db01 mysql-5.5.52]# ln -s /application/mysql-5.5.52/ /application/mysql
5、復(fù)制MySQL配置文件到/etc目錄下
[root@db01 mysql-5.5.52]# \cp /application/mysql/support-files/my-small.cnf /etc/my.cnf
6、配置環(huán)境變量
[root@db01 mysql-5.5.52]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile [root@db01 mysql-5.5.52]# tail -1 /etc/profile export PATH=/application/mysql/bin:$PATH [root@db01 mysql-5.5.52]# source /etc/profile [root@db01 mysql-5.5.52]# echo $PATH /application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
7、賦予目錄用戶(hù)組
[root@db01 mysql-5.5.52]# chown -R mysql.mysql /application/mysql/
8、執(zhí)行數(shù)據(jù)庫(kù)初始化腳本
[root@db01 mysql-5.5.52]# cd /application/mysql/scripts/ [root@db01 scripts]# ./mysql_install_db \ > --basedir=/application/mysql-5.5.52 \ > --datadir=/application/mysql-5.5.52/data \ > --user=mysql Installing MySQL system tables... 161210 15:00:47 [Note] /application/mysql-5.5.52/bin/mysqld (mysqld 5.5.52) starting as process 21047 ... OK Filling help tables... 161210 15:00:48 [Note] /application/mysql-5.5.52/bin/mysqld (mysqld 5.5.52) starting as process 21054 ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /application/mysql-5.5.52/bin/mysqladmin -u root password 'new-password' /application/mysql-5.5.52/bin/mysqladmin -u root -h db01 password 'new-password' Alternatively you can run: /application/mysql-5.5.52/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /application/mysql-5.5.52 ; /application/mysql-5.5.52/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /application/mysql-5.5.52/mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/
上面有兩個(gè)OK就表示初始化數(shù)據(jù)庫(kù)完成
9、配置啟動(dòng)MySQL
[root@db01 scripts]# cd [root@db01 ~]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld [root@db01 ~]# chmod +x /etc/init.d/mysqld [root@db01 ~]# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld [root@db01 ~]# /etc/init.d/mysqld start Starting MySQL... SUCCESS!
啟動(dòng)報(bào)錯(cuò)
#/etc/init.d/mysqld start
(1)啟動(dòng)文件保存
/etc/init.d/mysqld: line 276: cd: /usr/local/mysql: 沒(méi)有那個(gè)文件或目錄 Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
解決:
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
(2)MySQL啟動(dòng)報(bào)錯(cuò)
/etc/init.d/mysqld start 報(bào)錯(cuò): [root@mysql mysql]# /etc/init.d/mysqld start Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/mysql.pid).
問(wèn)題所在:mysql初始化出錯(cuò)
解決:
1.清空數(shù)據(jù)data目錄
rm -f /application/mysql/data/*
2.重新初始化mysql
/application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/
3.接著從初始化步驟后的步驟重新操作
netstat -lntup|grep mysql
10、加入開(kāi)機(jī)自啟動(dòng)
[root@db01 ~]# chkconfig mysqld on [root@db01 ~]# chkconfig --list mysqld mysqld 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
11、檢查端口
[root@db01 ~]# netstat -lntup | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 21333/mysqld
到這里MySQL數(shù)據(jù)庫(kù)就安裝完畢啦 O(∩_∩)O~~?。?!