LAMP是Linux Apache MySQL PHP的簡寫;linux是操做系統,Apache是一個web服務軟件,mysql數據庫軟件,PHP是一個腳本語言(目前不少網站都是php語言編寫,google,百度,淘寶,猿課論壇等)。php
LAMP就是將Apache、mysql、php裝在Linux系統上;咱們能夠將Apache和PHP裝在一臺機器上,將mysql裝在另外一臺機器上,也能夠將3個軟件裝在同一臺機器上。可是apache和php須要在同一臺機器上,這是由於PHP是做爲Apache的一個模塊存在的,它們必須在一塊兒。html
Apache和php是一個總體,php是一個模塊的形式和apache結合在一塊兒,apache不能直接和mysql直接進行交互,它只能經過php的模塊去 mysql中拿數據,php拿到數據後交給apache,apache再交給用戶。mysql
Php和mysql相連,去取數據的操做行爲叫作動態請求。linux
• 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內部測試版本web
MySQL的幾個經常使用安裝包:rpm、源碼、二進制免編譯sql
二進制包是區分平臺的,centos7以前的版本都是區分32位和64位,centos7直接選擇64位安裝。數據庫
[root@linux-128 src]# uname –i //查看linux是多少位 x86_64
[root@linux-128 ~]# cd /usr/local/src //建議將全部軟件包都放在這個目錄下
下載地址到r.aminglinux.com找最新的下載apache
[root@linux-128 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@linux-128 src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@linux-128 src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql [root@linux-128 ~]# cd /usr/local/mysql [root@linux-128 mysql]# ls bin data include man README share support-files COPYING docs lib mysql-test scripts sql-bench
[root@linux-128 mysql]# useradd -s /sbin/nologin mysql
[root@linux-128 mysql]# mkdir /data
[root@linux-128 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql //--user=mysql 以用戶mysql身份運行,--datadir=/data/mysql存放數據庫的目錄 ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper //這裏出現了錯誤,緣由是缺乏包 perl-Module-Install 能夠使用yum list 來查看缺乏包 [root@linux-128 mysql]# yum list |grep perl |grep -i dumper Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast perl-Data-Dumper.x86_64 2.145-3.el7 base perl-Data-Dumper-Concise.noarch 2.020-6.el7 epel perl-Data-Dumper-Names.noarch 0.03-17.el7 epel perl-XML-Dumper.noarch 0.81-17.el7 base 安裝perl-Data-Dumper包 [root@linux-128 mysql]# yum install -y perl-Data-Dumper
而後在執行一次vim
[root@linux-128 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 若是看到兩個OK說明執行正確,或者echo $? 結果爲0 也表示執行正確。 [root@linux-128 mysql]# echo $? 0
Mysql的配置文件在/usr/local/mysql/support-files/目錄下my-default.cnf,它是msyql的模板配置文件centos
[root@linux-128 mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf cp:是否覆蓋"/etc/my.cnf"? y //這裏已經存在文件my.cnf,這是以前系統rpm安裝留下的,咱們能夠查看它是那個包安裝的 [root@linux-128 mysql]# rpm -qf /etc/my.cnf mariadb-libs-5.5.52-1.el7.x86_64
咱們這裏直接按「y」覆蓋便可
[root@linux-128 mysql]# vim /etc/my.cnf [mysqld] # Remove leading # and set to the amount of RAM for the most important data # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. basedir = /usr/local/mysql //mysql的安裝目錄 datadir = /data/mysql //存放數據庫的目錄 port = 3306 //端口 # server_id = ..... //mysql的ID號,作主從的時候要用到 socket = /tmp/mysql.sock //mysql服務監聽的套件字地址,也是用來通訊的。 # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@linux-128 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@linux-128 mysql]# vim /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql
[root@linux-128 mysql]# chmod 755 /etc/init.d/mysqld
[root@linux-128 mysql]# chkconfig --add mysqld
[root@linux-128 mysql]# chkconfig mysqld on
[root@linux-128 mysql]# service mysqld start Starting MySQL.Logging to '/data/mysql/linux-128.err'. . SUCCESS!
若是啓動不了,請到/data/mysql/目錄下查看錯誤日誌,這個日誌一般是主機名.err
[root@linux-128 mysql]# ps aux |grep mysqld root 2808 0.0 0.0 11776 1572 pts/0 S 23:56 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/linux-128.pid mysql 2970 1.5 23.9 973064 449420 pts/0 Sl 23:56 0:01 /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/linux-128.err --pid-file=/data/mysql/linux-128.pid --socket=/tmp/my.sock --port=3306 root 2998 0.0 0.0 112676 972 pts/0 S+ 23:58 0:00 grep --color=auto mysqld
[root@linux-128 mysql]# netstat -lnp |grep mysqld tcp6 0 0 :::3306 :::* LISTEN 2970mysqld unix 2 [ ACC ] STREAM LISTENING 33024 2970/mysqld /tmp/my.sock
若是咱們不知道mysql的啓動文件,咱們還能夠使用命令行的方法來啓動mysql 先關閉以前打開的mysql
[root@linux-128 mysql]# service mysqld stop Shutting down MySQL.. SUCCESS!
執行命令行
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &