Apache和PHP是一個總體,由於PHP是以一個模塊的形式和Apache結合在一塊兒,可是Apache不能直接和MySQL去鏈接,只能經過PHP這個模塊去MySQL中提取數據,拿到數據後,PHP把這個結果交給Apache,Apache再交給用戶。html
PHP和MySQL交互數據的操做、行爲,稱爲 動態請求。python
rpm包——>直接yum安裝便可mysql
源碼包——>linux
二進制免編譯包——>這種包至關因而在發佈以前,先在一臺linux服務器上作了編譯,編譯完以後,把編譯完成的文件從新安排放到一個目錄下去,而後在打包壓縮,最後再發布git
[root@hf-01 ~]# cd /usr/local/src/ [root@hf-01 src]# ls httpd-2.2.34 httpd-2.2.34.tar.gz [root@hf-01 src]#
[root@hf-01 src]# uname -a //查看平臺,是多少位的 Linux hf-01 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@hf-01 src]#
[root@hf-01 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz --2017-12-12 04:39:17-- 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 560KB/s 用時 9m 41s 2017-12-12 04:49:03 (529 KB/s) - 已保存 「mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz」 [314581668/314581668]) [root@hf-01 src]#
[root@hf-01 src]# ls mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz [root@hf-01 src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 解壓文件過程
[root@hf-01 mysql]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql [root@hf-01 mysql]#
[root@hf-01 src]# cd !$ cd /usr/local/mysql [root@hf-01 mysql]#
[root@hf-01 mysql]# ls bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files [root@hf-01 mysql]#
[root@hf-01 mysql]# useradd mysql [root@hf-01 mysql]#
[root@hf-01 mysql]# mkdir /data/ [root@hf-01 mysql]#
[root@hf-01 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 [root@hf-01 mysql]#
[root@hf-01 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@hf-01 mysql]#
[root@hf-01 mysql]# yum install -y perl-Data-Dumper
[root@hf-01 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 [root@hf-01 mysql]#
[root@hf-01 mysql]# echo $? 141 [root@hf-01 mysql]#
[root@hf-01 mysql]# yum install -y libaio
[root@hf-01 mysql]# echo $? 0
[root@hf-01 mysql]# ls support-files/my-default.cnf support-files/my-default.cnf //mysql的模板配置文件 [root@hf-01 mysql]# ls /etc/my.cnf /etc/my.cnf //mysql的配置文件就叫作my.cnf,並且固定放在 /etc下 [root@hf-01 mysql]#
[root@hf-01 mysql]# rpm -qf /etc/my.cnf mariadb-libs-5.5.52-1.el7.x86_64 [root@hf-01 mysql]#
[root@hf-01 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@hf-01 mysql]# vim /etc/init.d/mysqld //編譯配置文件 把 basedir=/usr/local/mysql //指定你的程序目錄,放到/usr/local/mysql 下 把 datadir=/data/mysql //定義到/data/mysql 而後保存退出
[root@hf-01 mysql]# ls -l /etc/init.d/mysqld -rwxr-xr-x 1 root root 10902 12月 13 06:23 /etc/init.d/mysqld [root@hf-01 mysql]#
[root@hf-01 mysql]# chkconfig --add mysqld [root@hf-01 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@hf-01 mysql]#
[root@hf-01 mysql]# service mysqld start Starting MySQL.. SUCCESS! [root@hf-01 mysql]# ps aux |grep mysql //查看進程 root 2643 0.0 0.1 11772 1572 pts/0 S 06:33 0:00 /bin/sh /u mysql 2752 2.1 44.6 973552 451004 pts/0 Sl 06:33 0:01 /usr/localysql --log-error=/data/mysql/hf-01.err --pid-file=/data/mysql/hf-01.pid root 2781 0.0 0.0 112672 984 pts/0 R+ 06:35 0:00 grep --col [root@hf-01 mysql]# netstat -lntp //查看監聽的端口,3306端口 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1430/master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1192/sshd tcp6 0 0 ::1:25 :::* LISTEN 1430/master tcp6 0 0 :::3306 :::* LISTEN 2752/mysqld tcp6 0 0 :::22 :::* LISTEN 1192/sshd [root@hf-01 mysql]#
啓動方法: [root@hf-01 mysql]# service mysqld stop //首先先停掉mysqld服務 Shutting down MySQL.. SUCCESS! [root@hf-01 mysql]# !ps //查看mysqld進程是否還在 ps aux |grep mysql root 2814 0.0 0.0 112672 984 pts/0 R+ 06:45 0:00 grep --color=auto mysql [root@hf-01 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql & //命令行的方式啓動,先指定配置文件所在路徑,而後指定user用戶,指定datadir(這個datadir也能夠在my.cnf 文件中去定義的),再加一個& 符號,丟到後臺去 [1] 2910 [root@hf-01 mysql]# 171213 06:54:55 mysqld_safe Logging to '/data/mysql/hf-01.err'. 171213 06:54:55 mysqld_safe Starting mysqld daemon with databases from /data/mysql [root@hf-01 mysql]# !ps //查看進程是否啓動成功 ps aux |grep mysql root 2910 0.0 0.1 113268 1608 pts/0 S 06:54 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql mysql 3006 11.0 44.6 973552 451328 pts/0 Sl 06:54 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/hf-01.err --pid-file=/data/mysql/hf-01.pid root 3029 0.0 0.0 112672 984 pts/0 R+ 06:55 0:00 grep --color=auto mysql [root@hf-01 mysql]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1430/master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1192/sshd tcp6 0 0 ::1:25 :::* LISTEN 1430/master tcp6 0 0 :::3306 :::* LISTEN 3006/mysqld tcp6 0 0 :::22 :::* LISTEN 1192/sshd [root@hf-01 mysql]#
[root@hf-01 mysql]# killall mysqld [root@hf-01 mysql]# 171213 07:22:21 mysqld_safe mysqld from pid file /data/mysql/hf-01.pid ended [1]+ 完成 /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql [root@hf-01 mysql]# !ps ps aux |grep mysql root 3075 0.0 0.0 112672 984 pts/0 R+ 07:22 0:00 grep --color=auto mysql [root@hf-01 mysql]#