37.LAMP介紹 MySQL安裝

11.1 LAMP架構介紹php

11.2 MySQL、MariaDB介紹java

11.3/11.4/11.5 MySQL安裝mysql

 

 

 

 

11.1 LAMP架構介紹linux

~1. Linux+Apache(httpd)+MySQL+PKP 的簡稱爲LAMP架構web

Linux指的是操做系統,例如centossql

Apache這裏的apache指的是提供web的服務軟件,他真正的名字是httpd。習慣上叫作Apacheshell

MySQL是存儲的一個軟件。存的是數據,是一些字符串數據庫

PHP是腳本語言。和shell相似可是比shell複雜。像C語言apache

~2. php網站 (Google、淘寶、百度、51cto博客、猿課論壇)這些都是用PHP寫的bootstrap

~3. Apache、MySQL、PHP這三個角色能夠在一臺機器、也能夠分開(httpd和PHP要在一塊兒,MySQL能夠單獨一臺機器)

 

~4.httpd、PHP、MySQL三者如何工做

Apache和PHP是一個總體(由於要在一臺服務器上),是由於PHP是以一個模塊的形式和Apache結合在一塊兒的。Apache不能直接和MySQL相互的打交道,只能經過PHP這個模塊去MySQL裏面拿數據,拿到數據以後PHP再把這個結果交給Apache,Apache再交給用戶。其中,PHP和MySQL相連,去取數據這種的行爲叫作 動態的請求

那什麼叫動態,是叫靜態:好比咱們訪問猿課論壇,首先咱們得登陸吧,登陸的過程就是動態的過程。就像咱們上面說的,咱們登陸論壇,把帳號密碼交給Apache,Apache經過PHP去MySQL裏面找這個帳號密碼是否是匹配的。而後再把Apache再把這個結果交給咱們用戶。這就是動態的請求

咱們登陸論壇的時候,會有圖片,好比論壇的logo。咱們用戶向Apache請求的時候,他並無去MySQL打交道。而是去咱們linux的某一個目錄下去找。這就是靜態的請求

MySQL裏面不能存圖片、文件。那他裏面存的是,像用戶名 密碼、還有咱們發的帖子、還有積分

 

 

 

 

 

----------------------------------------------------------------------------------------------------------------------------------------------------

 

 

11.2 MySQL/MariaDB介紹:

 

MySQL是一個關係型數據庫,由mysql ab公司開發,mysql在2008年被sun公司(java)收購(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)發行候選版本(即即將成爲GA版本)。Beta開放測試版本(公測)。Alpha內部測試版本(內測)

 

 

 

----------------------------------------------------------------------------------------------------------------------------------------------------

 

 

11.3/11.4/11.5 MySQL安裝:

 

 

MySQL的幾個經常使用的安裝包: rpm(直接yum)、源碼包、二進制免編譯(可指定目錄,相似於rpm)

 

二進制免編譯方法:

cd /usr/local/src

wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

tar zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql

cd /usr/local/mysql

useradd mysql

mkdir /data/

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

cp support-files/my-default.cnf /etc/my.cnf

cp support-files/mysql.server /etc/init.d/mysqld

vi /etc/init.d/mysqld

定義basedir和datadir

basedir=/usr/local/mysql

datadir=/data/mysql

/etc/init.d/mysqld start 用這個命令把mysqld啓動起來

(chkconfig --add mysqld 開機啓動。chkconfig --list並查看一下列表)

也能夠用service mysqld start用這個命令把mysql啓動起來

也能夠用命令行的方式把它啓動起來:

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &

其中--defaults-file=/etc/my.cnf是指定他配置文件所在的路徑

用這種命令行的方式把它啓動起來,關閉的話,只能用killall mysql,把它kill掉。固然咱們也能夠用kill pid來殺死這個進程。可是儘可能用killall,由於mysql在讀寫的時候,有一部分還未寫入到磁盤,只是暫時保存在內存中,咱們要是直接kill pid這個進程的話,容易形成數據丟失。killall的話會等完成讀寫的時候,在殺死這個進程

因此,注意:當咱們在遇到當mysql的進程始終殺不死,等了一分鐘尚未殺死,ps aux還會有進程,那說明數據量很大,正在寫入到磁盤裏去。這個時候不要輕易的用kill -9去殺進程,這樣很是有可能丟數據,甚至損壞表

 

mysql有兩個經常使用的引擎,innodb(比較大) myisam(比較小,存儲空間都比較小) 本課只作瞭解

 

實例:

[root@localhost ~]# uname -a

root@localhost 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@localhost ~]# cd /usr/local/src

[root@localhost src]#wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

[root@localhost src]# tar -zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

[root@localhost src]# mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql

[root@localhost src]# cd /usr/local/mysql

[root@localhost mysql]# ls

bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files

[root@localhost mysql]# useradd mysql

[root@localhost mysql]# mkdir /data/

[root@localhost 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腳本的,提示少了perl模塊。因此咱們要安裝。不知道名字,模糊搜索一下

也可去網站將這個提示搜索一下,www.google.com www.bing.com www.baidu.com

[root@localhost mysql]# yum list | grep -i dumper 咱們先搜索一下,-i不分大小寫。咱們若是不清楚究竟是依賴哪一個包,就全安裝上

perl-Data-Dumper.x86_64                     2.145-3.el7                @base    
perl-XML-Dumper.noarch                      0.81-17.el7                base

[root@localhost mysql]# yum install -y perl-Data-Dumper 咱們知道,因此就安裝這個了

阿鑫在執行那個命令的時候,還提示了Installing MySQL system tables...2018-07-27 23:01:12 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).百度後 安裝了libaio*,就解決了(萬能的百度)

[root@localhost mysql]# yum install libaio* -y

已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 libaio.x86_64.0.0.3.109-13.el7 將被 安裝
---> 軟件包 libaio-devel.x86_64.0.0.3.109-13.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

===============================================================================================================================================================================================
 Package                                          架構                                       版本                                               源                                        大小
===============================================================================================================================================================================================
正在安裝:
 libaio                                           x86_64                                     0.3.109-13.el7                                     base                                      24 k
 libaio-devel                                     x86_64                                     0.3.109-13.el7                                     base                                      13 k

事務概要
===============================================================================================================================================================================================
安裝  2 軟件包

總下載量:37 k
安裝大小:46 k
Downloading packages:
(1/2): libaio-0.3.109-13.el7.x86_64.rpm                                                                                                                                 |  24 kB  00:00:00     
(2/2): libaio-devel-0.3.109-13.el7.x86_64.rpm                                                                                                                           |  13 kB  00:00:00     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
總計                                                                                                                                                           107 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.x86_64 0:0.3.109-13.el7                                                              libaio-devel.x86_64 0:0.3.109-13.el7

[root@axinlinux-01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

Installing MySQL system tables...2019-07-11 11:31:45 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-11 11:31:45 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-07-11 11:31:45 0 [Note] ./bin/mysqld (mysqld 5.6.43) starting as process 2012 ...
2019-07-11 11:31:45 2012 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-07-11 11:31:45 2012 [Note] InnoDB: The InnoDB memory heap is disabled
2019-07-11 11:31:45 2012 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-07-11 11:31:45 2012 [Note] InnoDB: Memory barrier is not used
2019-07-11 11:31:45 2012 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-07-11 11:31:45 2012 [Note] InnoDB: Using Linux native AIO
2019-07-11 11:31:45 2012 [Note] InnoDB: Using CPU crc32 instructions
2019-07-11 11:31:45 2012 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-07-11 11:31:45 2012 [Note] InnoDB: Completed initialization of buffer pool
2019-07-11 11:31:45 2012 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2019-07-11 11:31:45 2012 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2019-07-11 11:31:45 2012 [Note] InnoDB: Database physically writes the file full: wait...
2019-07-11 11:31:45 2012 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2019-07-11 11:31:46 2012 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2019-07-11 11:31:47 2012 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2019-07-11 11:31:47 2012 [Warning] InnoDB: New log files created, LSN=45781
2019-07-11 11:31:47 2012 [Note] InnoDB: Doublewrite buffer not found: creating new
2019-07-11 11:31:47 2012 [Note] InnoDB: Doublewrite buffer created
2019-07-11 11:31:47 2012 [Note] InnoDB: 128 rollback segment(s) are active.
2019-07-11 11:31:47 2012 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-07-11 11:31:47 2012 [Note] InnoDB: Foreign key constraint system tables created
2019-07-11 11:31:47 2012 [Note] InnoDB: Creating tablespace and datafile system tables.
2019-07-11 11:31:47 2012 [Note] InnoDB: Tablespace and datafile system tables created.
2019-07-11 11:31:47 2012 [Note] InnoDB: Waiting for purge to start
2019-07-11 11:31:47 2012 [Note] InnoDB: 5.6.43 started; log sequence number 0
2019-07-11 11:31:47 2012 [Note] Binlog end
2019-07-11 11:31:47 2012 [Note] InnoDB: FTS optimize thread exiting.
2019-07-11 11:31:47 2012 [Note] InnoDB: Starting shutdown...
2019-07-11 11:31:49 2012 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2019-07-11 11:31:49 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-11 11:31:49 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-07-11 11:31:49 0 [Note] ./bin/mysqld (mysqld 5.6.43) starting as process 2034 ...
2019-07-11 11:31:49 2034 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-07-11 11:31:49 2034 [Note] InnoDB: The InnoDB memory heap is disabled
2019-07-11 11:31:49 2034 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-07-11 11:31:49 2034 [Note] InnoDB: Memory barrier is not used
2019-07-11 11:31:49 2034 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-07-11 11:31:49 2034 [Note] InnoDB: Using Linux native AIO
2019-07-11 11:31:49 2034 [Note] InnoDB: Using CPU crc32 instructions
2019-07-11 11:31:49 2034 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-07-11 11:31:49 2034 [Note] InnoDB: Completed initialization of buffer pool
2019-07-11 11:31:49 2034 [Note] InnoDB: Highest supported file format is Barracuda.
2019-07-11 11:31:49 2034 [Note] InnoDB: 128 rollback segment(s) are active.
2019-07-11 11:31:49 2034 [Note] InnoDB: Waiting for purge to start
2019-07-11 11:31:49 2034 [Note] InnoDB: 5.6.43 started; log sequence number 1625977
2019-07-11 11:31:50 2034 [Note] Binlog end
2019-07-11 11:31:50 2034 [Note] InnoDB: FTS optimize thread exiting.
2019-07-11 11:31:50 2034 [Note] InnoDB: Starting shutdown...
2019-07-11 11:31:51 2034 [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 localhost.localdomain 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

那咱們怎麼知道有沒有成功呢。查看有沒有兩個 OK。或者直接 echo $? 是否是0

[root@localhost mysql]# echo $? 務必在執行完上一條命令以後立刻作。這個命令是檢驗上一條步驟是否是對的

0

[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost mysql]# vi /etc/init.d/mysqld

【mysql】前面的#去掉

basedir=/usr/local/mysql
datadir=/data/mysql
port = 3306 
server_id = 133

[root@localhost mysql]# ls -l !$ 把它chmod成755,固然默認就是755

chmod 755 /etc/init.d/mysql

ls -l /etc/init.d/mysqld 
-rwxr-xr-x. 1 root root 10644 7月  11 13:26 /etc/init.d/mysqld

[root@localhost mysql]# chkconfig --add mysqld 可讓他開機啓動

[root@localhost 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:關

[root@localhost mysql]# service mysqld start 能夠把它啓動起來

/etc/init.d/mysqld: line 33: [mysqld]: command not found
/etc/init.d/mysqld: line 48: port: command not found
/etc/init.d/mysqld: line 49: server_id: command not found
/etc/init.d/mysqld: line 50: socket: command not found
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
. SUCCESS!

Starting MySQL SUCCESS! SUCCESS說明啓動成功

[root@localhost mysql]# 180727 23:28:20 mysqld_safe A mysqld process already exists

^C

[root@localhost mysql]# ps aux | grep mysql 看一下進程列表

root       2154  0.0  0.1  11812  1632 pts/0    S    13:29   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql      2250  1.2 45.0 1302748 449820 pts/0  Sl   13:29   0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --usermysql --log-error=localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid
root       2276  0.0  0.0 112724   992 pts/0    S+   13:31   0:00 grep --color=auto mysql

[root@localhost mysql]# netstat -lntp 看一下監聽的網絡端口

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      895/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1041/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2250/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      895/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1041/master
相關文章
相關標籤/搜索