標籤:LAMP MySQL
LAMP簡介
LAMP=Linux+Apache(httpd)+MySQL+PHP
Apache與httpd是相輔相成的,必須在一起
Apache+MySQL+PHP可以同時安裝在一台機器上;
MySQL安裝
源檔案:http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
模組支援安裝包:perl-Data-Dumper.x86_64
下載MySQL安裝包
[[email protected] ~]# cd /usr/local/src/[[email protected] src]# lshttpd-2.2.34 httpd-2.2.34.tar.gz[[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
解壓並移動改名到安裝路徑
[[email protected] src]# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz[[email protected] src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql[[email protected] src]# ls /usr/local/apache2 bin etc games include lib lib64 libexec mysql sbin share src[[email protected] src]# ls /usr/local/mysql/bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files[[email protected] src]#
注意:/usr/local/mysql中的mysql不要提前建立,一定要是沒有此檔案夾才能移動;否則/mysql檔案夾下面是/mysql-5.6.36-linux-glibc2.5-x86_64檔案夾;
建立mysql使用者
建立一個mysql使用者,用來方便後面調用mysql資料庫
useradd mysql
建立/data目錄
[[email protected] src]# cd /usr/local/mysql/[[email protected] mysql]# lsbin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files[[email protected] mysql]#[[email protected] mysql]# mkdir /data/[[email protected] mysql]# lsbin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files[[email protected] mysql]#
安裝資料庫指定mysql資料庫的目錄與使用者名稱,錯誤提示處理;
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
將mysql的使用者使用者名稱指定為mysql,資料庫目錄指定為剛剛建立的/data/mysql目錄;
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysqlFATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:Data::Dumper[[email protected] mysql]#
此時提示缺少Dumper模組
尋找dumper模組包
yum list |grep perl |grep -i dumper
列出含有perl模組,不區分大小寫dumper包;
[[email protected] mysql]# yum list |grep perl |grep -i dumperperl-Data-Dumper.x86_64 2.145-3.el7 base perl-XML-Dumper.noarch 0.81-17.el7 base [[email protected] mysql]#
安裝模組支援包
yum install -y perl-Data-Dumper.x86_64
繼續執行指定目錄與使用者名稱,用echo $?檢查命令是否成功
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql[[email protected] mysql]# echo $?0[[email protected] mysql]#
複製配置模板到etc下(預設有)
[[email protected] mysql]# cp support-files/my-default.cnf /etc/my.cnfcp:是否覆蓋"/etc/my.cnf"? n[[email protected] mysql]# ls /etc/my.cnf/etc/my.cnf[[email protected] mysql]#
修改/etc/my.cnf設定檔
[[email protected] mysql]# vim /etc/my.cnf[[email protected] mysql]# cat /etc/my.cnf
[mysqld] datadir=/data/mysql socket=/tmp/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security risks> symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]#log-error=/var/log/mariadb/mariadb.log#pid-file=/var/run/mariadb/mariadb.pid## include all files from the config directory##!includedir /etc/my.cnf.d[[email protected] mysql]#
將datadir與socket修改,其他注釋掉;
設定開機啟動
cp support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld
1指定目錄
basedir=/usr/local/mysql
datadir=/data/mysql
2添加開機啟動項mysql
chkconfig --add mysqld
3查看開機啟動項
chkconfig --list
如果看到mysql服務,345都是on則是成功;
指定345開啟命令
chkconfig --level 345 mysql on
啟動於關閉mysql服務
開啟mysqld服務
service mysqld start
查詢mysql是否啟動
ps aux |grep mysqld
查詢啟動服務的連接埠
netstat -lntp
關閉mysql服務
killall mysqld
LAMP簡介與MySQL安裝