LAMP架構介紹與MySQL二進位制包安裝
阿新 • • 發佈:2018-11-25
LAMP架構介紹
- Linux + Apache(httpd) + MySQL + PHP
- PHP網站(Google、淘寶、百度)
- 三個角色可以在一臺機器、也可以分開(httpd和PHP要在一起)
httpd、PHP、MySQL工作關係圖
PHP去MySQL中讀取資料是個“動態”請求過程。
MySQL/Mariadb介紹
- MySQL是一個關係型資料庫,由mysql ab公司開發,mysql在2008年被sun公司收購(10億美金),2009年sun公司被oracle公司收購(74億美金)
- MySQL官網https://www.mysql.com
- MySQL5.6變化比較大,5.7效能上有很大提升
- Mariadb為MySQL的一個分支,官網https://mariadb.com
- Mariadb主要由SkySQL公司(現更名為MariaDB公司)維護,SkySQL公司由MySQL原作者帶領大部分原班人馬創立。
- Community 社群版本,Enterprise 企業版,GA(Generally Available) 通用版本,在生產環境中用的,DMR(Development Milestone Release) 開發里程碑釋出版,RC(Release Candidate) 發行候選版本,Beta開發測試版,Alpha內部測試版本
安裝MySQL
- MySQL的幾個常用按轉包: rpm、原始碼、二進位制免編譯
用二進位制免編譯安裝(對效能沒有較高的要求的情況下)Mysql5.7
[[email protected] ~]# uname -a # 檢視系統位數
Linux test-a 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] ~]# cd /usr/local/src/
# 下載二進位制包
[[email protected] src]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[[email protected] src]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 把解壓後的目錄重新命名mysql後移動到/usr/local下
[[email protected] src]# mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
[[email protected] mysql]# useradd mysql # 建立mysql使用者
[[email protected] mysql]# mkdir /data/ # 為mysql建立資料儲存目錄
[[email protected] mysql]# ./bin/mysql_install_db # 需要指定資料目錄和建議使用mysqld --initialize來初始化資料庫
2018-11-12 06:33:14 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-11-12 06:33:14 [ERROR] The data directory needs to be specified.
[[email protected] mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql
2018-11-11T22:37:03.945687Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-11T22:37:06.436762Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-11T22:37:06.779631Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-11T22:37:06.842918Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 519df254-e602-11e8-91f0-000c29b95699.
2018-11-11T22:37:06.845661Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-11T22:37:06.847683Z 1 [Note] A temporary password is generated for [email protected]: (a1ckckbsd2A
# 資料庫初始化完成
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld # 拷貝mysql啟動指令碼到/etc/init.d/下並重命名為mysqld
[[email protected] mysql]# vi /etc/init.d/mysqld
#更改兩行配置如下
# basedir=/usr/loca/mysql
# datadir=/data/mysql
[[email protected] mysql]# chkconfig --add mysqld # 設定mysqld以後啟動為跟隨系統自啟動
[[email protected] mysql]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
iprdump 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprinit 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprupdate 0:off 1:off 2:on 3:on 4:on 5:on 6:off
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# 新建mysql 配置檔案/etc/my.cnf(有則清空),新增如下內容
[mysql]
socket = /usr/local/mysql/mysql.sock
# The MySQL server
[mysqld]
port = 3306
socket = /usr/local/mysql/mysql.sock
#skip-grant-tables
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/db.err
pid-file=/usr/local/mysql/mysqld.pid
character-set-server = utf8
[[email protected] lib]# service mysqld start #啟動報錯,新增對應的檔案db.err
Starting MySQL.2018-11-11T23:24:48.581799Z mysqld_safe error: log-error set to '/usr/local/mysql/db.err', 't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/usr/local/mysql/mysqld.pid).
[[email protected] lib]# touch db.err
[[email protected] lib]# chown mysql:mysql db.err
[[email protected] mysql]# service mysqld start # 再次失敗
Starting MySQL................................................................... ERROR! The server quit wPID file (/usr/local/mysql/mysqld.pid).
#是因為mysql目錄的檔案需要屬於mysql使用者
[[email protected] mysql]# chown mysql:mysql -R .
[[email protected] mysql]# service mysqld start
Starting MySQL......... SUCCESS!
#另外一種啟動方式,其中--defaults-file必須緊接著命令後面,可以沒有,預設/etc/my.cnf
[[email protected] mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
# 停止服務
[[email protected] mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS!
# 另外一種方法
[[email protected] mysql]# killall mysqld # 不要使用kill -9 pid,有可能丟資料