LAMP架構介紹與MySQL二進制包安裝

LAMP架構介紹

  • Linux + Apache(httpd) + MySQL + PHP
  • PHP網站(Google、淘寶、百度)
  • 三個角色能夠在一臺機器、也能夠分開(httpd和PHP要在一塊兒)

httpd、PHP、MySQL工做關係圖

PHP去MySQL中讀取數據是個「動態」請求過程。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.7linux

[root@test-a ~]# 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

[root@test-a ~]# cd /usr/local/src/  
# 下載二進制包
[root@test-a src]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz  
[root@test-a src]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 把解壓後的目錄重命名mysql後移動到/usr/local下
[root@test-a src]# mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
[root@test-a mysql]# useradd mysql # 建立mysql用戶
[root@test-a mysql]# mkdir /data/  # 爲mysql建立數據存儲目錄  
[root@test-a 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.

[root@test-a 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 root@localhost: (a1ckckbsd2A
# 數據庫初始化完成

[root@test-a mysql]# cp support-files/mysql.server /etc/init.d/mysqld # 拷貝mysql啓動腳本到/etc/init.d/下並重命名爲mysqld
[root@test-a mysql]# vi /etc/init.d/mysqld
#更改兩行配置以下
# basedir=/usr/loca/mysql
# datadir=/data/mysql
[root@test-a mysql]# chkconfig --add mysqld  # 設置mysqld之後啓動爲跟隨系統自啓動
[root@test-a 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

[root@test-a 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).
 
 [root@test-a lib]# touch db.err
[root@test-a lib]# chown mysql:mysql db.err

[root@test-a mysql]#  service mysqld start # 再次失敗
Starting MySQL................................................................... ERROR! The server quit wPID file (/usr/local/mysql/mysqld.pid).

#是由於mysql目錄的文件須要屬於mysql用戶
[root@test-a mysql]# chown mysql:mysql -R .
[root@test-a mysql]#  service mysqld start
Starting MySQL......... SUCCESS!

#另一種啓動方式,其中--defaults-file必須緊接着命令後面,能夠沒有,默認/etc/my.cnf
[root@test-a mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &

# 中止服務
[root@test-a mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS!
# 另一種方法
[root@test-a mysql]# killall mysqld # 不要使用kill -9 pid,有可能丟數據
相關文章
相關標籤/搜索