標籤:LAMP MySQL MariaDB
11.1 LAMP架構介紹
·LAMP = Linux + Apache(httpd) + MySQL + PHP
三個角色可以在一台機器、也可以分開(httpd和PHP要在一起)
Apache通過PHP的模組到MySQL中提取資料(動態請求)
網站登入的過程就是一個動態請求
訪問網站的圖片就是靜態請求
11.2 MySQL、MariaDB介紹
MySQL是一個關係型資料庫,由mysql ab公司開發,mysql在2008年被sun公司收購(10億美元),2009年sun公司被oracle公司收購(74億美元)
MySQL官網https://www.mysql.com 最新版本5.7GA/8.0DMR
MySQL5.6變化比較大,5.7效能上有很大提升
Mariadb為MySQL的一個分支,官網https://mariadb.com/最新版本10.2
MariaDB主要由SkySQL公司(現更名為MariaDB公司)維護,SkySQL公司由MySQL原作者帶領大部分原班人馬創立.
Mariadb5.5版本對應MySQL的5.5,10.0對應MySQL5.6
Community 社區版本(免費),Enterprise 企業版,GA(Generally Available)指通用版本,在生產環境中用的,DMR(Development Milestone Release)開發裡程碑發布版,RC(Release Candidate)發行候選版本,Beta開放測試版本,Alpha自我裝載版本
11.3/11.4/11.5 MySQL安裝
MySQL的幾個常用安裝包:rpm、源碼、二進位免編譯
二進位免編譯包:不用編譯,拿來就用
下載包到目錄:/usr/local/src
[[email protected] ~]# cd /usr/local/src/[[email protected] src]# ll總用量 22176-rw-r--r--. 1 root root 0 1月 6 22:20 ]drwxr-xr-x. 12 1001 1001 4096 1月 6 22:39 httpd-2.2.34-rw-r--r--. 1 root root 7684419 7月 10 2017 httpd-2.2.34.tar.gzdrwxr-xr-x. 17 1000 1000 4096 1月 6 23:10 php-5.6.30-rw-r--r--. 1 root root 15011816 1月 19 2017 php-5.6.30.tar.bz2[[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz--2018-01-29 22:30:42-- http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-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長度:314581668 (300M) [application/octet-stream]正在儲存至: “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz”100%[============================================================================================================================>] 314,581,668 1.37MB/s 用時 3m 45s 2018-01-29 22:34:28 (1.33 MB/s) - 已儲存 “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz” [314581668/314581668])解壓gz包,並把目錄移動到/usr/local/下,並改名為mysql(不可放到mysql下)[[email protected] src]# tar -zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz [[email protected] src]# ll總用量 329388-rw-r--r--. 1 root root 0 1月 6 22:20 ]drwxr-xr-x. 12 1001 1001 4096 1月 6 22:39 httpd-2.2.34-rw-r--r--. 1 root root 7684419 7月 10 2017 httpd-2.2.34.tar.gzdrwxr-xr-x. 13 root root 191 1月 29 22:40 mysql-5.6.35-linux-glibc2.5-x86_64-rw-r--r--. 1 root root 314581668 11月 28 2016 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gzdrwxr-xr-x. 17 1000 1000 4096 1月 6 23:10 php-5.6.30-rw-r--r--. 1 root root 15011816 1月 19 2017 php-5.6.30.tar.bz2[[email protected] src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql [[email protected] src]# cd /usr/local/mysql/[[email protected] mysql]# ll總用量 48drwxr-xr-x. 2 root root 4096 1月 29 22:40 bin-rw-r--r--. 1 7161 31415 17987 11月 28 2016 COPYINGdrwxr-xr-x. 3 root root 18 1月 29 22:40 datadrwxr-xr-x. 2 root root 55 1月 29 22:40 docsdrwxr-xr-x. 3 root root 4096 1月 29 22:40 includedrwxr-xr-x. 3 root root 4096 1月 29 22:40 libdrwxr-xr-x. 4 root root 30 1月 29 22:40 mandrwxr-xr-x. 10 root root 4096 1月 29 22:40 mysql-test-rw-r--r--. 1 7161 31415 2496 11月 28 2016 READMEdrwxr-xr-x. 2 root root 30 1月 29 22:40 scriptsdrwxr-xr-x. 28 root root 4096 1月 29 22:40 sharedrwxr-xr-x. 4 root root 4096 1月 29 22:40 sql-benchdrwxr-xr-x. 2 root root 136 1月 29 22:40 support-files
初始化
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysqlFATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:Data::Dumper##缺少perl dumper包[[email protected] mysql]# yum list |grep perl |grep -i dumper##先嘗試能不能搜到perl-Data-Dumper.x86_64 2.145-3.el7 baseperl-Data-Dumper-Concise.noarch 2.020-6.el7 epelperl-Data-Dumper-Names.noarch 0.03-17.el7 epelperl-XML-Dumper.noarch 0.81-17.el7 base[[email protected] mysql]# yum install -y perl-Data-Dumper.x86_64(過程省略)[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql(過程省略)[[email protected] mysql]# echo $?0[[email protected] mysql]# cp support-files/my-default.cnf /etc/my.cnf
(如果系統內建/etc/my.cnf,那麼可以直接編輯)
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld[[email protected] mysql]# vim /etc/init.d/mysqld
[[email protected] mysql]# chkconfig --add mysqld##設定服務開機啟動[[email protected] mysql]# 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:關[[email protected] mysql]# service mysqld startStarting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.... SUCCESS![[email protected] mysql]# ps aux |grep mysqldroot 1532 0.0 0.1 11768 1564 pts/0 S 22:38 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pidmysql 1667 40.8 45.2 973060 452004 pts/0 Sl 22:38 0:02 /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/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sockroot 1697 0.0 0.0 112676 984 pts/0 R+ 22:38 0:00 grep --color=auto mysqld[[email protected] mysql]# netstat -lntpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 922/sshdtcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1031/mastertcp6 0 0 :::22 :::* LISTEN 922/sshdtcp6 0 0 ::1:25 :::* LISTEN 1031/mastertcp6 0 0 :::3306 :::* LISTEN 1667/mysqld
如果在沒有配置模板/etc/my.cnf,則用命令列的方法:
[[email protected] mysql]# service mysqld stopShutting down MySQL.. SUCCESS![[email protected] mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &[1] 1848[[email protected] mysql]# 180131 22:45:06 mysqld_safe Logging to '/data/mysql/localhost.localdomain.err'.180131 22:45:06 mysqld_safe Starting mysqld daemon with databases from /data/mysql[[email protected] mysql]# !psps aux |grep mysqldroot 1848 0.0 0.1 113264 1588 pts/0 S 22:45 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysqlmysql 1971 1.3 45.1 973060 451300 pts/0 Sl 22:45 0:00 /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/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sockroot 1994 0.0 0.0 112676 980 pts/0 R+ 22:45 0:00 grep --color=auto mysqld(--defaults-file= 指定設定檔)
命令列啟動的服務,killall mysqld關閉
進程殺不死,資料太大需要寫入,不要強制kill -9殺進程,不然非常容易丟資料或者損壞表
2018-2-26 9周4次課 LAMP、MySQL安裝