LAMP架構、MYSQL安裝
阿新 • • 發佈:2018-02-27
MySQLLAMP架構
1.lamp包含什麽
- httpd、PHP、MySQL三者如何工作
MySQL存儲用戶名,密碼一些數據,圖片之類的放在靜態文件裏
MySQL_MariaDB介紹
MySQL安裝
1.首先下載軟件包
[root@weixing01 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz --2018-02-26 21:12:00-- http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-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 長度:316320366 (302M) [application/octet-stream] 正在保存至: “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz” 100%[====================================>] 316,320,366 525KB/s 用時 11m 2s 2018-02-26 21:23:02 (467 KB/s) - 已保存 “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz” [316320366/316320366])
2.解壓縮
tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
3.移動目錄並改名
[root@weixing01 src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
4.進入mysql目錄
[root@weixing01 src]# cd /usr/local/mysql/ [root@weixing01 mysql]# ls bin data include man README share support-files COPYING docs lib mysql-test scripts sql-bench
5.創建用戶,目錄並初始化
[root@weixing01 mysql]# useradd mysql [root@weixing01 mysql]# mkdir /data/ [root@weixing01 mysql]# ls /data/ [root@weixing01 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
6.有報錯,需要安裝perl包:
[root@weixing01 mysql]# yum install -y perl-Data-Dumper
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.ustc.edu.cn
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 perl-Data-Dumper.x86_64.0.2.145-3.el7 將被 安裝
--> 解決依賴關系完成
7.完成後繼續執行,有報錯:
[root@weixing01 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@weixing01 mysql]# yum install -y libaio-devel
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.ustc.edu.cn
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 libaio-devel.x86_64.0.0.3.109-13.el7 將被 安裝
--> 正在處理依賴關系 libaio(x86-64) = 0.3.109-13.el7,它被軟件包 libaio-devel-0.3.109-13.el7.x86_64 需要
--> 正在檢查事務
---> 軟件包 libaio.x86_64.0.0.3.109-13.el7 將被 安裝
8.初始化:
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...2018-02-26 22:25:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-02-26 22:25:59 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-02-26 22:25:59 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 1622 ...
2018-02-26 22:25:59 1622 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-02-26 22:25:59 1622 [Note] InnoDB: The InnoDB memory heap is disabled
2018-02-26 22:25:59 1622 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-02-26 22:25:59 1622 [Note] InnoDB: Memory barrier is not used
2018-02-26 22:25:59 1622 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-02-26 22:25:59 1622 [Note] InnoDB: Using Linux native AIO
9.執行完成後馬上執行
[root@weixing01 mysql]# echo $?
0
檢驗上一條是否正確,0為正確
10.復制配置文件,或更改自帶文件
[root@weixing01 mysql]# cp support-files/my-default.cnf /etc/my.cnf^C
[root@weixing01 mysql]# ls /etc/my.cnf
/etc/my.cnf
[root@weixing01 mysql]# rpm -qf /etc/my.cnf
mariadb-libs-5.5.56-2.el7.x86_64
[root@weixing01 mysql]# vim /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
11.復制啟動腳本
[root@weixing01 mysql]# ls support-files/
binary-configure my-default.cnf mysql-log-rotate
magic mysqld_multi.server mysql.server
[root@weixing01 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
12.更改啟動腳本:
[root@weixing01 mysql]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
13.設置開機啟動
[root@weixing01 mysql]# chkconfig --add mysqld
[root@weixing01 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:關
14.立刻啟動程序:
[root@weixing01 mysql]# service mysqld start
Starting MySQL.Logging to ‘/data/mysql/weixing01.err‘.
. SUCCESS!
15.采用命令行方式啟動:
[root@weixing01 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
[1] 2101
[root@weixing01 mysql]# 180226 22:44:15 mysqld_safe Logging to ‘/data/mysql/weixing01.err‘.
180226 22:44:15 mysqld_safe Starting mysqld daemon with databases from /data/mysql
16.用killall殺死程序,比kill保險,不會在磁盤讀寫時損壞數據
[root@weixing01 mysql]# killall mysqld
[root@weixing01 mysql]# 180226 22:47:13 mysqld_safe mysqld from pid file /data/mysql/weixing01.pid ended
[1]+ 完成 /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
[root@weixing01 mysql]# ps aux |grep mysql
root 2398 0.0 0.0 112676 984 pts/0 R+ 22:47 0:00 grep --color=auto mysql
LAMP架構、MYSQL安裝