11.1 LAMP架構介紹
LAMP架構: L:linux 系統(OS)、 A:Apache(httpd)Web服務、M:MySQL(存儲數據庫)、P:PHP(Web腳本語言)php
如今不少主流的網站都用LAMP架構開發的:如google、淘寶、百度、51cto、論壇等。css
Apache、MySQL、PHP能夠安裝在同一臺服務器上,也能夠分開安裝。html
可是Apache與PHP必須安裝在同一臺機器上,MySQL能夠單獨安裝。java
由於在LAMP架構中,PHP是以Apache的一個模塊方式存在的:mysql
一、用戶瀏覽器 ---> 發出訪問請求 ---> Apache服務器;linux
二、Apache服務器接收到用戶請求後,進行處理;web
三、httpd服務處理靜態文件:圖片css等;sql
四、php Module模塊處理動態請求:php頁面解析、MySQL用戶數據等;數據庫
五、 Apache服務器把處理結果返回給用戶 ---> 用戶瀏覽器展現請求結果給用戶。apache
11.2 MySQL、MariaDB介紹
mysql是一種關係型數據庫,由mysql ab公司開發的。又來被sun公司收購,sun公司又被oracle公司收購,因此如今mysql是屬於oracle公司,以前是免費的,後面就開始商業化了。
mysql從5.6版本開始比以前的版本變化比較大。5.7開始性能又有很大的提高。
後來mysql的創始人原班人馬繼續開發出一個分支產品:Mariadb,主要由開源社區進行維護,並免費提供給用戶使用。
Mariadb 5.5對應MySQL 5.5,後面10.0對應MySQL 5.6。
通常在生產環境中,用GA(Generally Available)通用版本,比較穩定。
還有一個RC(Release Candidate)髮型候選版本,也比較穩定。
如今還有不少公司在使用MySQL 5.二、5.四、5.5等較老的版本。通常咱們使用5.6版本就能夠了。
11.3/11.4/11.5 MySQL安裝
mysql安裝:通常有rpm包安裝、源碼包安裝、二進制免編譯安裝(發佈前已經編譯好)等方式。
咱們這裏採用二進制免編譯安裝: 一、下載二進制免編譯包:通常咱們把軟件下載到 /usr/local/src 下(先cd進入該目錄,用wget下載),先查看咱們linux系統是什麼版本的(64位、32位),下載相對應的安裝包。
[root@lgs-02 src]# uname -a Linux lgs-02 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@lgs-02 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz -bash: wget: 未找到命令 [root@lgs-02 src]# yum install -y wget 已加載插件:fastestmirror base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/2): extras/7/x86_64/primary_db | 143 kB 00:00:00 (2/2): updates/7/x86_64/primary_db | 2.0 MB 00:00:06 Loading mirror speeds from cached hostfile * base: mirrors.sohu.com * extras: mirrors.aliyun.com * updates: mirrors.163.com 正在解決依賴關係 --> 正在檢查事務 ---> 軟件包 wget.x86_64.0.1.14-15.el7_4.1 將被 安裝 --> 解決依賴關係完成 依賴關係解決 ============================================================================================================================================================== Package 架構 版本 源 大小 ============================================================================================================================================================== 正在安裝: wget x86_64 1.14-15.el7_4.1 base 547 k 事務概要 ============================================================================================================================================================== 安裝 1 軟件包 總下載量:547 k 安裝大小:2.0 M Downloading packages: wget-1.14-15.el7_4.1.x86_64.rpm | 547 kB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝 : wget-1.14-15.el7_4.1.x86_64 1/1 驗證中 : wget-1.14-15.el7_4.1.x86_64 1/1 已安裝: wget.x86_64 0:1.14-15.el7_4.1 完畢! [root@lgs-02 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz --2018-05-23 17:56:02-- http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz 正在解析主機 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140 正在鏈接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已鏈接。 已發出 HTTP 請求,正在等待迴應... 200 OK 長度:316320366 (302M) [application/octet-stream] 正在保存至: 「mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz」 100%[====================================================================================================================>] 316,320,366 1.02MB/s 用時 5m 59s 2018-05-23 18:02:01 (860 KB/s) - 已保存 「mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz」 [316320366/316320366]) [root@lgs-02 src]# ls mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
二、解壓tar文件包。
[root@lgs-02 src]# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/oracle.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/mysql.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/Adabas.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/empress.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/mysql-4.0.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/interbase.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/interbase-dialect3.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/msql.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/mysql-3.22.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/sybase.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/ms-sql.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/limits/interbase-dialect1.cfg mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-create mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/bench-count-distinct mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/crash-me mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-alter-table mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-big-tables mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/graph-compare-results mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-connect mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/bench-init.pl mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/innotest1b mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-insert mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-select [root@lgs-02 src]# ls mysql-5.6.36-linux-glibc2.5-x86_64 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
三、把解壓後的二進制包移動到安裝目錄,並更名爲mysql目錄
[root@lgs-02 src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql/ [root@lgs-02 src]# ls mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@lgs-02 src]# ls /usr/local/ bin etc games include lib lib64 libexec mysql sbin share src [root@lgs-02 src]# ls /usr/local/mysql/ bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
四、建立一個系統的普通用戶,用於運行mysql服務。
[root@lgs-02 src]# useradd mysql [root@lgs-02 src]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:997:User for polkitd:/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin chrony:x:998:996::/var/lib/chrony:/sbin/nologin mysql:x:1000:1000::/home/mysql:/bin/bash
五、建立存放mysql數據庫與表的目錄
[root@lgs-02 ~]# mkdir -p /data/mysql [root@lgs-02 ~]# ls -l /data/ 總用量 0 drwxr-xr-x. 2 root root 6 5月 23 18:20 mysql [root@lgs-02 ~]# ls -l /data/mysql/ 總用量 0
六、初始化mysql二進制包:先進入/usr/local/mysql/,再初始化。
[root@lgs-02 ~]# cd /usr/local/mysql/ [root@lgs-02 mysql]# ls bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files [root@lgs-02 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ -bash: ./scripts/mysql_install_db: /usr/bin/perl: 壞的解釋器: 沒有那個文件或目錄
報錯:缺乏perl命令,則查找perl命令須要安裝的包,而後進行安裝。
[root@lgs-02 mysql]# yum provides "/*/perl" 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.sohu.com * extras: mirrors.aliyun.com * updates: mirrors.163.com base/7/x86_64/filelists_db | 6.9 MB 00:00:08 extras/7/x86_64/filelists_db | 517 kB 00:00:00 updates/7/x86_64/filelists_db | 1.3 MB 00:00:01 389-ds-base-1.3.7.5-18.el7.x86_64 : 389 Directory Server (base) 源 :base 匹配來源: 文件名 :/usr/lib64/dirsrv/perl 389-ds-base-1.3.7.5-19.el7_5.x86_64 : 389 Directory Server (base) 源 :updates 匹配來源: 文件名 :/usr/lib64/dirsrv/perl 389-ds-base-1.3.7.5-21.el7_5.x86_64 : 389 Directory Server (base) 源 :updates 匹配來源: 文件名 :/usr/lib64/dirsrv/perl 1:bash-completion-2.1-6.el7.noarch : Programmable completion for Bash 源 :base 匹配來源: 文件名 :/usr/share/bash-completion/helpers/perl freeradius-perl-3.0.13-8.el7_4.x86_64 : Perl support for freeradius 源 :base 匹配來源: 文件名 :/etc/raddb/mods-available/perl 文件名 :/etc/raddb/mods-config/perl freeradius-perl-3.0.13-9.el7_5.x86_64 : Perl support for freeradius 源 :updates 匹配來源: 文件名 :/etc/raddb/mods-available/perl 文件名 :/etc/raddb/mods-config/perl graphviz-perl-2.30.1-21.el7.x86_64 : Perl extension for graphviz 源 :base 匹配來源: 文件名 :/usr/lib64/graphviz/perl jakarta-oro-javadoc-2.0.8-16.el7.noarch : Javadoc for jakarta-oro 源 :base 匹配來源: 文件名 :/usr/share/javadoc/jakarta-oro/org/apache/oro/text/perl kernel-debug-devel-3.10.0-862.el7.x86_64 : Development package for building kernel modules to match the debug kernel 源 :base 匹配來源: 文件名 :/usr/src/kernels/3.10.0-862.el7.x86_64.debug/tools/perf/scripts/perl kernel-debug-devel-3.10.0-862.2.3.el7.x86_64 : Development package for building kernel modules to match the debug kernel 源 :updates 匹配來源: 文件名 :/usr/src/kernels/3.10.0-862.2.3.el7.x86_64.debug/tools/perf/scripts/perl kernel-debug-devel-3.10.0-862.3.2.el7.x86_64 : Development package for building kernel modules to match the debug kernel 源 :updates 匹配來源: 文件名 :/usr/src/kernels/3.10.0-862.3.2.el7.x86_64.debug/tools/perf/scripts/perl kernel-devel-3.10.0-862.el7.x86_64 : Development package for building kernel modules to match the kernel 源 :base 匹配來源: 文件名 :/usr/src/kernels/3.10.0-862.el7.x86_64/tools/perf/scripts/perl kernel-devel-3.10.0-862.2.3.el7.x86_64 : Development package for building kernel modules to match the kernel 源 :updates 匹配來源: 文件名 :/usr/src/kernels/3.10.0-862.2.3.el7.x86_64/tools/perf/scripts/perl kernel-devel-3.10.0-862.3.2.el7.x86_64 : Development package for building kernel modules to match the kernel 源 :updates 匹配來源: 文件名 :/usr/src/kernels/3.10.0-862.3.2.el7.x86_64/tools/perf/scripts/perl libpurple-perl-2.10.11-7.el7.x86_64 : Perl scripting support for libpurple 源 :base 匹配來源: 文件名 :/usr/lib64/purple-2/perl pcp-testsuite-3.12.2-5.el7.x86_64 : Performance Co-Pilot (PCP) test suite 源 :base 匹配來源: 文件名 :/var/lib/pcp/testsuite/perl perf-3.10.0-862.el7.x86_64 : Performance monitoring for the Linux kernel 源 :base 匹配來源: 文件名 :/usr/libexec/perf-core/scripts/perl perf-3.10.0-862.2.3.el7.x86_64 : Performance monitoring for the Linux kernel 源 :updates 匹配來源: 文件名 :/usr/libexec/perf-core/scripts/perl perf-3.10.0-862.3.2.el7.x86_64 : Performance monitoring for the Linux kernel 源 :updates 匹配來源: 文件名 :/usr/libexec/perf-core/scripts/perl 4:perl-5.16.3-292.el7.x86_64 : Practical Extraction and Report Language 源 :base 匹配來源: 文件名 :/usr/bin/perl 4:perl-tests-5.16.3-292.el7.x86_64 : The Perl test suite 源 :base 匹配來源: 文件名 :/usr/libexec/perl5-tests/perl-tests/t/lib/warnings/perl pidgin-perl-2.10.11-7.el7.x86_64 : Perl scripting support for Pidgin 源 :base 匹配來源: 文件名 :/usr/lib64/pidgin/perl 2:texlive-base-2012-38.20130427_r30134.el7.noarch : TeX Live filesystem, metadata and licenses shipped in text form 源 :base 匹配來源: 文件名 :/usr/share/texlive/texmf-dist/scripts/context/perl 文件名 :/usr/share/texlive/texmf-dist/scripts/xetex/perl [root@lgs-02 mysql]# yum install -y perl 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.sohu.com * extras: mirrors.aliyun.com * updates: mirrors.163.com 正在解決依賴關係 --> 正在檢查事務 ---> 軟件包 perl.x86_64.4.5.16.3-292.el7 將被 安裝 --> 正在處理依賴關係 perl-libs = 4:5.16.3-292.el7,它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Socket) >= 1.3,它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Scalar::Util) >= 1.10,它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl-macros,它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl-libs,它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(threads::shared),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(threads),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(constant),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Time::Local),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Time::HiRes),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Storable),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Socket),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Scalar::Util),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Pod::Simple::XHTML),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Pod::Simple::Search),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Getopt::Long),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Filter::Util::Call),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(File::Temp),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(File::Spec::Unix),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(File::Spec::Functions),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(File::Spec),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(File::Path),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Exporter),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Cwd),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 perl(Carp),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在處理依賴關係 libperl.so()(64bit),它被軟件包 4:perl-5.16.3-292.el7.x86_64 須要 --> 正在檢查事務 ---> 軟件包 perl-Carp.noarch.0.1.26-244.el7 將被 安裝 ---> 軟件包 perl-Exporter.noarch.0.5.68-3.el7 將被 安裝 ---> 軟件包 perl-File-Path.noarch.0.2.09-2.el7 將被 安裝 ---> 軟件包 perl-File-Temp.noarch.0.0.23.01-3.el7 將被 安裝 ---> 軟件包 perl-Filter.x86_64.0.1.49-3.el7 將被 安裝 ---> 軟件包 perl-Getopt-Long.noarch.0.2.40-3.el7 將被 安裝 --> 正在處理依賴關係 perl(Pod::Usage) >= 1.14,它被軟件包 perl-Getopt-Long-2.40-3.el7.noarch 須要 --> 正在處理依賴關係 perl(Text::ParseWords),它被軟件包 perl-Getopt-Long-2.40-3.el7.noarch 須要 ---> 軟件包 perl-PathTools.x86_64.0.3.40-5.el7 將被 安裝 ---> 軟件包 perl-Pod-Simple.noarch.1.3.28-4.el7 將被 安裝 --> 正在處理依賴關係 perl(Pod::Escapes) >= 1.04,它被軟件包 1:perl-Pod-Simple-3.28-4.el7.noarch 須要 --> 正在處理依賴關係 perl(Encode),它被軟件包 1:perl-Pod-Simple-3.28-4.el7.noarch 須要 ---> 軟件包 perl-Scalar-List-Utils.x86_64.0.1.27-248.el7 將被 安裝 ---> 軟件包 perl-Socket.x86_64.0.2.010-4.el7 將被 安裝 ---> 軟件包 perl-Storable.x86_64.0.2.45-3.el7 將被 安裝 ---> 軟件包 perl-Time-HiRes.x86_64.4.1.9725-3.el7 將被 安裝 ---> 軟件包 perl-Time-Local.noarch.0.1.2300-2.el7 將被 安裝 ---> 軟件包 perl-constant.noarch.0.1.27-2.el7 將被 安裝 ---> 軟件包 perl-libs.x86_64.4.5.16.3-292.el7 將被 安裝 ---> 軟件包 perl-macros.x86_64.4.5.16.3-292.el7 將被 安裝 ---> 軟件包 perl-threads.x86_64.0.1.87-4.el7 將被 安裝 ---> 軟件包 perl-threads-shared.x86_64.0.1.43-6.el7 將被 安裝 --> 正在檢查事務 ---> 軟件包 perl-Encode.x86_64.0.2.51-7.el7 將被 安裝 ---> 軟件包 perl-Pod-Escapes.noarch.1.1.04-292.el7 將被 安裝 ---> 軟件包 perl-Pod-Usage.noarch.0.1.63-3.el7 將被 安裝 --> 正在處理依賴關係 perl(Pod::Text) >= 3.15,它被軟件包 perl-Pod-Usage-1.63-3.el7.noarch 須要 --> 正在處理依賴關係 perl-Pod-Perldoc,它被軟件包 perl-Pod-Usage-1.63-3.el7.noarch 須要 ---> 軟件包 perl-Text-ParseWords.noarch.0.3.29-4.el7 將被 安裝 --> 正在檢查事務 ---> 軟件包 perl-Pod-Perldoc.noarch.0.3.20-4.el7 將被 安裝 --> 正在處理依賴關係 perl(parent),它被軟件包 perl-Pod-Perldoc-3.20-4.el7.noarch 須要 --> 正在處理依賴關係 perl(HTTP::Tiny),它被軟件包 perl-Pod-Perldoc-3.20-4.el7.noarch 須要 ---> 軟件包 perl-podlators.noarch.0.2.5.1-3.el7 將被 安裝 --> 正在檢查事務 ---> 軟件包 perl-HTTP-Tiny.noarch.0.0.033-3.el7 將被 安裝 ---> 軟件包 perl-parent.noarch.1.0.225-244.el7 將被 安裝 --> 解決依賴關係完成 依賴關係解決 ============================================================================================================================================================== Package 架構 版本 源 大小 ============================================================================================================================================================== 正在安裝: perl x86_64 4:5.16.3-292.el7 base 8.0 M 爲依賴而安裝: perl-Carp noarch 1.26-244.el7 base 19 k perl-Encode x86_64 2.51-7.el7 base 1.5 M perl-Exporter noarch 5.68-3.el7 base 28 k perl-File-Path noarch 2.09-2.el7 base 26 k perl-File-Temp noarch 0.23.01-3.el7 base 56 k perl-Filter x86_64 1.49-3.el7 base 76 k perl-Getopt-Long noarch 2.40-3.el7 base 56 k perl-HTTP-Tiny noarch 0.033-3.el7 base 38 k perl-PathTools x86_64 3.40-5.el7 base 82 k perl-Pod-Escapes noarch 1:1.04-292.el7 base 51 k perl-Pod-Perldoc noarch 3.20-4.el7 base 87 k perl-Pod-Simple noarch 1:3.28-4.el7 base 216 k perl-Pod-Usage noarch 1.63-3.el7 base 27 k perl-Scalar-List-Utils x86_64 1.27-248.el7 base 36 k perl-Socket x86_64 2.010-4.el7 base 49 k perl-Storable x86_64 2.45-3.el7 base 77 k perl-Text-ParseWords noarch 3.29-4.el7 base 14 k perl-Time-HiRes x86_64 4:1.9725-3.el7 base 45 k perl-Time-Local noarch 1.2300-2.el7 base 24 k perl-constant noarch 1.27-2.el7 base 19 k perl-libs x86_64 4:5.16.3-292.el7 base 688 k perl-macros x86_64 4:5.16.3-292.el7 base 43 k perl-parent noarch 1:0.225-244.el7 base 12 k perl-podlators noarch 2.5.1-3.el7 base 112 k perl-threads x86_64 1.87-4.el7 base 49 k perl-threads-shared x86_64 1.43-6.el7 base 39 k 事務概要 ============================================================================================================================================================== 安裝 1 軟件包 (+26 依賴軟件包) 總下載量:11 M 安裝大小:36 M Downloading packages: (1/27): perl-Carp-1.26-244.el7.noarch.rpm | 19 kB 00:00:00 (2/27): perl-Exporter-5.68-3.el7.noarch.rpm | 28 kB 00:00:00 (3/27): perl-File-Temp-0.23.01-3.el7.noarch.rpm | 56 kB 00:00:00 (4/27): perl-File-Path-2.09-2.el7.noarch.rpm | 26 kB 00:00:00 (5/27): perl-Filter-1.49-3.el7.x86_64.rpm | 76 kB 00:00:00 (6/27): perl-HTTP-Tiny-0.033-3.el7.noarch.rpm | 38 kB 00:00:00 (7/27): perl-Pod-Escapes-1.04-292.el7.noarch.rpm | 51 kB 00:00:00 (8/27): perl-PathTools-3.40-5.el7.x86_64.rpm | 82 kB 00:00:00 (9/27): perl-Getopt-Long-2.40-3.el7.noarch.rpm | 56 kB 00:00:00 (10/27): perl-Pod-Perldoc-3.20-4.el7.noarch.rpm | 87 kB 00:00:00 (11/27): perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm | 36 kB 00:00:00 (12/27): perl-Socket-2.010-4.el7.x86_64.rpm | 49 kB 00:00:00 (13/27): perl-Pod-Usage-1.63-3.el7.noarch.rpm | 27 kB 00:00:00 (14/27): perl-Pod-Simple-3.28-4.el7.noarch.rpm | 216 kB 00:00:00 (15/27): perl-Time-HiRes-1.9725-3.el7.x86_64.rpm | 45 kB 00:00:00 (16/27): perl-Text-ParseWords-3.29-4.el7.noarch.rpm | 14 kB 00:00:00 (17/27): perl-Time-Local-1.2300-2.el7.noarch.rpm | 24 kB 00:00:00 (18/27): perl-Storable-2.45-3.el7.x86_64.rpm | 77 kB 00:00:00 (19/27): perl-macros-5.16.3-292.el7.x86_64.rpm | 43 kB 00:00:00 (20/27): perl-constant-1.27-2.el7.noarch.rpm | 19 kB 00:00:00 (21/27): perl-parent-0.225-244.el7.noarch.rpm | 12 kB 00:00:00 (22/27): perl-podlators-2.5.1-3.el7.noarch.rpm | 112 kB 00:00:00 (23/27): perl-Encode-2.51-7.el7.x86_64.rpm | 1.5 MB 00:00:02 (24/27): perl-threads-shared-1.43-6.el7.x86_64.rpm | 39 kB 00:00:00 (25/27): perl-threads-1.87-4.el7.x86_64.rpm | 49 kB 00:00:00 (26/27): perl-libs-5.16.3-292.el7.x86_64.rpm | 688 kB 00:00:01 (27/27): perl-5.16.3-292.el7.x86_64.rpm | 8.0 MB 00:00:10 -------------------------------------------------------------------------------------------------------------------------------------------------------------- 總計 1.1 MB/s | 11 MB 00:00:10 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝 : 1:perl-parent-0.225-244.el7.noarch 1/27 正在安裝 : perl-HTTP-Tiny-0.033-3.el7.noarch 2/27 正在安裝 : perl-podlators-2.5.1-3.el7.noarch 3/27 正在安裝 : perl-Pod-Perldoc-3.20-4.el7.noarch 4/27 正在安裝 : 1:perl-Pod-Escapes-1.04-292.el7.noarch 5/27 正在安裝 : perl-Text-ParseWords-3.29-4.el7.noarch 6/27 正在安裝 : perl-Encode-2.51-7.el7.x86_64 7/27 正在安裝 : perl-Pod-Usage-1.63-3.el7.noarch 8/27 正在安裝 : 4:perl-macros-5.16.3-292.el7.x86_64 9/27 正在安裝 : 4:perl-libs-5.16.3-292.el7.x86_64 10/27 正在安裝 : perl-Storable-2.45-3.el7.x86_64 11/27 正在安裝 : perl-Exporter-5.68-3.el7.noarch 12/27 正在安裝 : perl-constant-1.27-2.el7.noarch 13/27 正在安裝 : perl-Time-Local-1.2300-2.el7.noarch 14/27 正在安裝 : perl-Socket-2.010-4.el7.x86_64 15/27 正在安裝 : perl-Carp-1.26-244.el7.noarch 16/27 正在安裝 : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 17/27 正在安裝 : perl-PathTools-3.40-5.el7.x86_64 18/27 正在安裝 : perl-Scalar-List-Utils-1.27-248.el7.x86_64 19/27 正在安裝 : perl-File-Temp-0.23.01-3.el7.noarch 20/27 正在安裝 : perl-File-Path-2.09-2.el7.noarch 21/27 正在安裝 : perl-threads-shared-1.43-6.el7.x86_64 22/27 正在安裝 : perl-threads-1.87-4.el7.x86_64 23/27 正在安裝 : perl-Filter-1.49-3.el7.x86_64 24/27 正在安裝 : 1:perl-Pod-Simple-3.28-4.el7.noarch 25/27 正在安裝 : perl-Getopt-Long-2.40-3.el7.noarch 26/27 正在安裝 : 4:perl-5.16.3-292.el7.x86_64 27/27 驗證中 : perl-HTTP-Tiny-0.033-3.el7.noarch 1/27 驗證中 : perl-threads-shared-1.43-6.el7.x86_64 2/27 驗證中 : perl-Storable-2.45-3.el7.x86_64 3/27 驗證中 : perl-Exporter-5.68-3.el7.noarch 4/27 驗證中 : perl-constant-1.27-2.el7.noarch 5/27 驗證中 : perl-PathTools-3.40-5.el7.x86_64 6/27 驗證中 : 4:perl-macros-5.16.3-292.el7.x86_64 7/27 驗證中 : 1:perl-parent-0.225-244.el7.noarch 8/27 驗證中 : 4:perl-5.16.3-292.el7.x86_64 9/27 驗證中 : perl-File-Temp-0.23.01-3.el7.noarch 10/27 驗證中 : 1:perl-Pod-Simple-3.28-4.el7.noarch 11/27 驗證中 : perl-Time-Local-1.2300-2.el7.noarch 12/27 驗證中 : 4:perl-libs-5.16.3-292.el7.x86_64 13/27 驗證中 : perl-Socket-2.010-4.el7.x86_64 14/27 驗證中 : perl-Carp-1.26-244.el7.noarch 15/27 驗證中 : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 16/27 驗證中 : perl-Scalar-List-Utils-1.27-248.el7.x86_64 17/27 驗證中 : 1:perl-Pod-Escapes-1.04-292.el7.noarch 18/27 驗證中 : perl-Pod-Usage-1.63-3.el7.noarch 19/27 驗證中 : perl-Encode-2.51-7.el7.x86_64 20/27 驗證中 : perl-Pod-Perldoc-3.20-4.el7.noarch 21/27 驗證中 : perl-podlators-2.5.1-3.el7.noarch 22/27 驗證中 : perl-File-Path-2.09-2.el7.noarch 23/27 驗證中 : perl-threads-1.87-4.el7.x86_64 24/27 驗證中 : perl-Filter-1.49-3.el7.x86_64 25/27 驗證中 : perl-Getopt-Long-2.40-3.el7.noarch 26/27 驗證中 : perl-Text-ParseWords-3.29-4.el7.noarch 27/27 已安裝: perl.x86_64 4:5.16.3-292.el7 做爲依賴被安裝: perl-Carp.noarch 0:1.26-244.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-PathTools.x86_64 0:3.40-5.el7 perl-Pod-Escapes.noarch 1:1.04-292.el7 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-292.el7 perl-macros.x86_64 4:5.16.3-292.el7 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7 完畢!
繼續初始化:
[root@lgs-02 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper
又報錯:缺乏Perl模塊的 Dumper。查找須要安裝的包,而後安裝後,再繼續初始化。
[root@lgs-02 mysql]# yum list|grep perl|grep -i dumper perl-Data-Dumper.x86_64 2.145-3.el7 base perl-XML-Dumper.noarch 0.81-17.el7 base [root@lgs-02 mysql]# yum install -y perl-Data-Dumper 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.sohu.com * extras: mirrors.aliyun.com * updates: mirrors.163.com 正在解決依賴關係 --> 正在檢查事務 ---> 軟件包 perl-Data-Dumper.x86_64.0.2.145-3.el7 將被 安裝 --> 解決依賴關係完成 依賴關係解決 ============================================================================================================================================================== Package 架構 版本 源 大小 ============================================================================================================================================================== 正在安裝: perl-Data-Dumper x86_64 2.145-3.el7 base 47 k 事務概要 ============================================================================================================================================================== 安裝 1 軟件包 總下載量:47 k 安裝大小:97 k Downloading packages: perl-Data-Dumper-2.145-3.el7.x86_64.rpm | 47 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝 : perl-Data-Dumper-2.145-3.el7.x86_64 1/1 驗證中 : perl-Data-Dumper-2.145-3.el7.x86_64 1/1 已安裝: perl-Data-Dumper.x86_64 0:2.145-3.el7 完畢!
再繼續初始化:
[root@lgs-02 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
又報錯:缺乏libaio.so模塊,查找安裝模塊。
[root@lgs-02 mysql]# yum list|grep libaio libaio.i686 0.3.109-13.el7 base libaio.x86_64 0.3.109-13.el7 base libaio-devel.i686 0.3.109-13.el7 base libaio-devel.x86_64 0.3.109-13.el7 base [root@lgs-02 mysql]# yum install -y libaio-devel 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.sohu.com * extras: mirrors.aliyun.com * updates: mirrors.163.com 正在解決依賴關係 --> 正在檢查事務 ---> 軟件包 libaio-devel.x86_64.0.0.3.109-13.el7 將被 安裝 --> 正在處理依賴關係 libaio(x86-64) = 0.3.109-13.el7,它被軟件包 libaio-devel-0.3.109-13.el7.x86_64 須要 --> 正在檢查事務 ---> 軟件包 libaio.x86_64.0.0.3.109-13.el7 將被 安裝 --> 解決依賴關係完成 依賴關係解決 ============================================================================================================================================================== Package 架構 版本 源 大小 ============================================================================================================================================================== 正在安裝: libaio-devel x86_64 0.3.109-13.el7 base 13 k 爲依賴而安裝: libaio x86_64 0.3.109-13.el7 base 24 k 事務概要 ============================================================================================================================================================== 安裝 1 軟件包 (+1 依賴軟件包) 總下載量:37 k 安裝大小:46 k Downloading packages: (1/2): libaio-devel-0.3.109-13.el7.x86_64.rpm | 13 kB 00:00:00 (2/2): libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00 -------------------------------------------------------------------------------------------------------------------------------------------------------------- 總計 114 kB/s | 37 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝 : libaio-0.3.109-13.el7.x86_64 1/2 正在安裝 : libaio-devel-0.3.109-13.el7.x86_64 2/2 驗證中 : libaio-0.3.109-13.el7.x86_64 1/2 驗證中 : libaio-devel-0.3.109-13.el7.x86_64 2/2 已安裝: libaio-devel.x86_64 0:0.3.109-13.el7 做爲依賴被安裝: libaio.x86_64 0:0.3.109-13.el7 完畢!
再再繼續初始化:
[root@lgs-02 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ Installing MySQL system tables...2018-05-23 18:44:50 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-05-23 18:44:50 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-05-23 18:44:50 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 1462 ... 2018-05-23 18:44:50 1462 [Note] InnoDB: Using atomics to ref count buffer pool pages 2018-05-23 18:44:50 1462 [Note] InnoDB: The InnoDB memory heap is disabled 2018-05-23 18:44:50 1462 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-05-23 18:44:50 1462 [Note] InnoDB: Memory barrier is not used 2018-05-23 18:44:50 1462 [Note] InnoDB: Compressed tables use zlib 1.2.3 2018-05-23 18:44:50 1462 [Note] InnoDB: Using Linux native AIO 2018-05-23 18:44:50 1462 [Note] InnoDB: Using CPU crc32 instructions 2018-05-23 18:44:50 1462 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2018-05-23 18:44:50 1462 [Note] InnoDB: Completed initialization of buffer pool 2018-05-23 18:44:50 1462 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2018-05-23 18:44:50 1462 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2018-05-23 18:44:50 1462 [Note] InnoDB: Database physically writes the file full: wait... 2018-05-23 18:44:50 1462 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2018-05-23 18:44:53 1462 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2018-05-23 18:45:03 1462 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2018-05-23 18:45:03 1462 [Warning] InnoDB: New log files created, LSN=45781 2018-05-23 18:45:03 1462 [Note] InnoDB: Doublewrite buffer not found: creating new 2018-05-23 18:45:03 1462 [Note] InnoDB: Doublewrite buffer created 2018-05-23 18:45:03 1462 [Note] InnoDB: 128 rollback segment(s) are active. 2018-05-23 18:45:03 1462 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-05-23 18:45:04 1462 [Note] InnoDB: Foreign key constraint system tables created 2018-05-23 18:45:04 1462 [Note] InnoDB: Creating tablespace and datafile system tables. 2018-05-23 18:45:04 1462 [Note] InnoDB: Tablespace and datafile system tables created. 2018-05-23 18:45:04 1462 [Note] InnoDB: Waiting for purge to start 2018-05-23 18:45:04 1462 [Note] InnoDB: 5.6.36 started; log sequence number 0 2018-05-23 18:45:05 1462 [Note] Binlog end 2018-05-23 18:45:05 1462 [Note] InnoDB: FTS optimize thread exiting. 2018-05-23 18:45:05 1462 [Note] InnoDB: Starting shutdown... 2018-05-23 18:45:07 1462 [Note] InnoDB: Shutdown completed; log sequence number 1625977 OK Filling help tables...2018-05-23 18:45:07 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-05-23 18:45:07 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-05-23 18:45:07 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 1484 ... 2018-05-23 18:45:07 1484 [Note] InnoDB: Using atomics to ref count buffer pool pages 2018-05-23 18:45:07 1484 [Note] InnoDB: The InnoDB memory heap is disabled 2018-05-23 18:45:07 1484 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-05-23 18:45:07 1484 [Note] InnoDB: Memory barrier is not used 2018-05-23 18:45:07 1484 [Note] InnoDB: Compressed tables use zlib 1.2.3 2018-05-23 18:45:07 1484 [Note] InnoDB: Using Linux native AIO 2018-05-23 18:45:07 1484 [Note] InnoDB: Using CPU crc32 instructions 2018-05-23 18:45:07 1484 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2018-05-23 18:45:07 1484 [Note] InnoDB: Completed initialization of buffer pool 2018-05-23 18:45:07 1484 [Note] InnoDB: Highest supported file format is Barracuda. 2018-05-23 18:45:07 1484 [Note] InnoDB: 128 rollback segment(s) are active. 2018-05-23 18:45:07 1484 [Note] InnoDB: Waiting for purge to start 2018-05-23 18:45:07 1484 [Note] InnoDB: 5.6.36 started; log sequence number 1625977 2018-05-23 18:45:07 1484 [Note] Binlog end 2018-05-23 18:45:07 1484 [Note] InnoDB: FTS optimize thread exiting. 2018-05-23 18:45:07 1484 [Note] InnoDB: Starting shutdown... 2018-05-23 18:45:09 1484 [Note] InnoDB: Shutdown completed; log sequence number 1625987 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: ./bin/mysqladmin -u root password 'new-password' ./bin/mysqladmin -u root -h lgs-02 password 'new-password' Alternatively you can run: ./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 . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com WARNING: Found existing config file ./my.cnf on the system. Because this file might be in use, it was not replaced, but was used in bootstrap (unless you used --defaults-file) and when you later start the server. The new default config file was created as ./my-new.cnf, please compare it with your file and take the changes you need. WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server
初始化完畢:進行檢驗是否安裝成功。echo $?:檢驗上一條命令是否運行成功,0爲成功。
[root@lgs-02 mysql]# echo $? 0
七、拷貝配置文件:並修改配置文件裏的定義的data目錄
[root@lgs-02 mysql]# ls bin COPYING data docs include lib man my.cnf my-new.cnf mysql-test README scripts share sql-bench support-files [root@lgs-02 mysql]# ls support-files/my-default.cnf support-files/my-default.cnf [root@lgs-02 mysql]# cp support-files/my-default.cnf /etc/my.cnf cp:是否覆蓋"/etc/my.cnf"? y [root@lgs-02 ~]# cat !$ cat /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
八、設置開機啓動mysql:拷貝啓動腳本、修改腳本中的mysql程序目錄和數據目錄、變動腳本運行權限、加入系統服務列表。
[root@lgs-02 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@lgs-02 ~]# ls -l /etc/init.d/mysqld -rwxr-xr-x. 1 root root 10565 5月 23 19:23 /etc/init.d/mysqld [root@lgs-02 ~]# vim !$ vim /etc/init.d/mysqld #!/bin/sh # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB # This file is public domain and comes with NO WARRANTY of any kind # MySQL daemon start/stop script. # Usually this is put in /etc/init.d (at least on machines SYSV R4 based # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql. # When this is done the mysql server will be started when the machine is # started and shut down when the systems goes down. # Comments to support chkconfig on RedHat Linux # chkconfig: 2345 64 36 # description: A very fast and reliable SQL database engine. # Comments to support LSB init script conventions ### BEGIN INIT INFO # Provides: mysql # Required-Start: $local_fs $network $remote_fs # Should-Start: ypbind nscd ldap ntpd xntpd # Required-Stop: $local_fs $network $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop MySQL # Description: MySQL is a very fast and reliable SQL database engine. ### END INIT INFO # If you install MySQL on some other places than /usr/local/mysql, then you # have to do one of the following things for this script to work: # # - Run this script from within the MySQL installation directory # - Create a /etc/my.cnf file with the following information: # [mysqld] # basedir=<path-to-mysql-installation-directory> # - Add the above to any other configuration file (for example ~/.my.ini) # and copy my_print_defaults to /usr/bin # - Add the path to the mysql-installation-directory to the basedir variable # below. # # If you want to affect other MySQL variables, you should make your changes # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files. # If you change base dir, you must also change datadir. These may get # overwritten by settings in the MySQL configuration files. basedir=/usr/local/mysql/ datadir=/data/mysql/ # Default value, in seconds, afterwhich the script should timeout waiting # for server start. # Value here is overriden by value in my.cnf. # 0 means don't wait at all # Negative numbers mean to wait indefinitely service_startup_timeout=900 # Lock directory for RedHat / SuSE. lockdir='/var/lock/subsys' lock_file_path="$lockdir/mysql" # The following variables are only set for letting mysql.server find things. [root@lgs-02 ~]# chmod 755 !$ chmod 755 /etc/init.d/mysqld [root@lgs-02 ~]# ls -l /etc/init.d/mysqld -rwxr-xr-x. 1 root root 10594 5月 23 19:25 /etc/init.d/mysqld [root@lgs-02 ~]# chkconfig --add mysqld [root@lgs-02 ~]# chkconfig --list 注:該輸出結果只顯示 SysV 服務,並不包含 原生 systemd 服務。SysV 配置數據 可能被原生 systemd 配置覆蓋。 要列出 systemd 服務,請執行 'systemctl list-unit-files'。 查看在具體 target 啓用的服務請執行 'systemctl list-dependencies [target]'。 mysqld 0:關 1:關 2:開 3:開 4:開 5:開 6:關 netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關 network 0:關 1:關 2:開 3:開 4:開 5:開 6:關
九、啓動mysqld服務:檢查進程、檢查監聽端口可以確認mysqld服務是否正常啓動。
用啓動腳本啓動:/etc/init.d/mysqld start
[root@lgs-02 ~]# /etc/init.d/mysqld start Starting MySQL.Logging to '/data/mysql/lgs-02.err'. ............ SUCCESS! #檢查 mysqld的進程 [root@lgs-02 ~]# ps aux |grep mysqld root 1584 0.4 0.0 113264 1624 pts/0 S 19:28 0:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql/ --pid-file=/data/mysql//lgs-02.pid mysql 1691 57.7 24.0 1300780 449560 pts/0 Sl 19:28 0:12 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/lgs-02.err --pid-file=/data/mysql//lgs-02.pid root 1739 0.0 0.0 112680 992 pts/0 S+ 19:28 0:00 grep --color=auto mysqld #檢查 mysqld的監聽端口3306 [root@lgs-02 ~]# netstat -lntp|grep mysqld tcp6 0 0 :::3306 :::* LISTEN 1691/mysqld
用service 命令啓動:
[root@lgs-02 ~]# service mysqld start Starting MySQL. SUCCESS! [root@lgs-02 ~]# ps aux |grep mysqld root 1772 0.1 0.0 11772 1592 pts/0 S 19:32 0:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql/ --pid-file=/data/mysql//lgs-02.pid mysql 1880 4.2 24.0 1300780 449544 pts/0 Sl 19:32 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/lgs-02.err --pid-file=/data/mysql//lgs-02.pid root 1904 0.0 0.0 112680 992 pts/0 S+ 19:33 0:00 grep --color=auto mysqld [root@lgs-02 ~]# netstat -lntp|grep mysqld tcp6 0 0 :::3306 :::* LISTEN 1880/mysqld
若是啓動腳本沒辦法放到/etc/init.d/ 下,能夠用命令行的方式啓動:指定配置文件路徑、啓動用戶、數據目錄
# $號:後臺運行 [root@lgs-02 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/ & [1] 2082 [root@lgs-02 ~]# 180523 19:38:14 mysqld_safe Logging to '/data/mysql/lgs-02.err'. 180523 19:38:14 mysqld_safe Starting mysqld daemon with databases from /data/mysql [root@lgs-02 ~]# ps aux |grep mysqld root 2082 0.0 0.0 113264 1616 pts/0 S 19:38 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/ mysql 2177 0.5 24.0 1300780 449536 pts/0 Sl 19:38 0:01 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/lgs-02.err --pid-file=/data/mysql/lgs-02.pid root 2200 0.0 0.0 112676 992 pts/0 R+ 19:42 0:00 grep --color=auto mysqld [root@lgs-02 ~]# netstat -lntp|grep mysqld tcp6 0 0 :::3306 :::* LISTEN 2177/mysqld
十、關閉mysql服務
#service命令關閉 [root@lgs-02 ~]# service mysqld stop Shutting down MySQL..180523 19:44:27 mysqld_safe mysqld from pid file /data/mysql/lgs-02.pid ended SUCCESS! [1]+ 完成 /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/ #啓動腳本方式關閉 [root@lgs-02 ~]# /etc/init.d/mysqld stop Shutting down MySQL.. SUCCESS! #killall 命令殺死進程關閉 [root@lgs-02 ~]# yum provides "/usr/bin/killa*" 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.sohu.com * extras: mirrors.aliyun.com * updates: mirrors.163.com psmisc-22.20-15.el7.x86_64 : Utilities for managing processes on your system 源 :base 匹配來源: 文件名 :/usr/bin/killall [root@lgs-02 ~]# yum install -y psmisc 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.sohu.com * extras: mirrors.aliyun.com * updates: mirrors.163.com 正在解決依賴關係 --> 正在檢查事務 ---> 軟件包 psmisc.x86_64.0.22.20-15.el7 將被 安裝 --> 解決依賴關係完成 依賴關係解決 ============================================================================================================================================================== Package 架構 版本 源 大小 ============================================================================================================================================================== 正在安裝: psmisc x86_64 22.20-15.el7 base 141 k 事務概要 ============================================================================================================================================================== 安裝 1 軟件包 總下載量:141 k 安裝大小:475 k Downloading packages: psmisc-22.20-15.el7.x86_64.rpm | 141 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝 : psmisc-22.20-15.el7.x86_64 1/1 驗證中 : psmisc-22.20-15.el7.x86_64 1/1 已安裝: psmisc.x86_64 0:22.20-15.el7 完畢! [root@lgs-02 ~]# service mysqld start Starting MySQL. SUCCESS! [root@lgs-02 ~]# ps aux |grep mysqld root 2711 0.5 0.0 11772 1596 pts/0 S 19:48 0:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql/ --pid-file=/data/mysql//lgs-02.pid mysql 2819 4.5 24.0 1300780 449548 pts/0 Sl 19:48 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/lgs-02.err --pid-file=/data/mysql//lgs-02.pid root 2843 0.0 0.0 112680 992 pts/0 S+ 19:48 0:00 grep --color=auto mysqld [root@lgs-02 ~]# killall mysqld [root@lgs-02 ~]# ps aux |grep mysqld root 2851 0.0 0.0 444 4 pts/0 R+ 19:48 0:00 grep --color=auto mysqld
killall mysqld:安全點,先會停掉讀寫操做,再把緩存數據寫完到磁盤,再中止進程服務。 # 別用 kill mysqld :會當即殺死進程,若是這時候還有數據寫入,會形成數據丟失 # 別用 kill -9 pid :嚴重會損壞庫和表
查看mysql的配置文件的路徑:
[root@lgs-02 ~]# /usr/local/mysql/bin/mysql --verbose --help|grep -A 1 'Default options' Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
MySQL有兩種引擎:innodb:比較大與oracle相似、myisam:存儲量比較小。