初识 LAMP
LAMP 是工作中常用的 web 部署架构之一。它由 linux、apache(httpd)、mysql 和 php 组成。其各个部件之间运作的关系如下图所示:
用户通过游览器访问服务端的 apache(httpd)服务,如果访问的是静态数据,就直接提取。如果访问的数据来自 mysql,那么就需要调用 php 模块与 mysql 建立关系读取数据。
Mysql 与 Mariadb
Mysql 是一个关系型数据库,由 mysql ab 公司开发,在 2008 年被 sun 公司收购,2009 年被 oracle 公司收购。mysql 最新版本是 5.7GA/8.0DMR。mysql 5.6 版本变化比较大,5.7 版本性能上有很大提升。
Mariadb 是 mysql 的一个分支,最新版本是 10.2 版本。它是由 Mysql 原作者带领大部分原班人马创立的 SkySQL 公司维护。
Mariadb5.5 版本对应 MySQL 的 5.5 版本, 10.0 版本对应 MySQL 的 5.6 版本。
- Tips:Community 社区版本,Enterprise 企业版,GA(Generally Available)指通用版本,在生产环境中用的,DMR(Development Milestone Release)开发里程碑发布版,RC(Release Candidate)发行候选版本,Beta开放测试版本,Alpha内部测试版本。
安装 Mysql
Mysql 的安装方式主要有 3 种,分别为 rpm、源码和二进制免编。译一般我们平时安装 MySQL 都是源码包安装的,但是由于它的编译需要很长的时间,建议安装二进制免编译包。可以到 MySQL 官方网站去下载,也可以其他镜像网站下载。
1、下载安装文件
- [[email protected] ~]# cd / usr / local / src[[email protected] src]# wget http: //mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
- --2017 - 07 - 21 06 : 40 : 22-- 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 555KB / s 用时 9m 36s
- 2017 - 07 - 21 06 : 49 : 59 (533 KB / s) - 已保存 "mysql - 5.6.35 - linux - glibc2.5 - x86_64.tar.gz" [314581668 / 314581668])
2、解压并移动
- [[email protected] src]# tar zxvf mysql - 5.6.35 - linux - glibc2.5 - x86_64.tar.gz mysql - 5.6.35 - linux - glibc2.5 - x86_64 / README mysql - 5.6.35 - linux - glibc2.5 - x86_64 / data / test / db.opt mysql - 5.6.35 - linux - glibc2.5 - x86_64 / lib / libmysqlclient.a...... [[email protected] src]# mv mysql - 5.6.35 - linux - glibc2.5 - x86_64 / usr / local / mysql
3、创建用户与文件夹
- [[email protected] local]# cd mysql / [[email protected] mysql]# ls bin data include man README share support - files COPYING docs lib mysql - test scripts sql - bench[[email protected] mysql]# useradd mysql[[email protected] mysql]# mkdir / data /
4、初始化数据库
- [[email protected] 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-Data-Dumper,使用 yum 安装上,重新初始化。
- [[email protected] mysql]# . / scripts / mysql_install_db --user = mysql --datadir = /data/my sql Installing MySQL system tables.... / bin / mysqld: error
- while loading shared librar ies: libaio.so.1 : cannot open shared object file: No such file or directory
运行出错,安装 libaio 和 libaio-dev 相关的包,重新初始化。
- [[email protected] mysql]# . / scripts / mysql_install_db --user = mysql --datadir = /data/mysql Installing MySQL system tables...2017 - 07 - 21 07 : 17 : 04 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation
- for more details).2017 - 07 - 21 07 : 17 : 04 0 [Note] Ignoring --secure - file - priv value as server is running with --bootstrap.2017 - 07 - 21 07 : 17 : 04 0 [Note] . / bin / mysqld (mysqld 5.6.35) starting as process 9822 ...2017 - 07 - 21 07 : 17 : 04 9822 [Note] InnoDB: Using atomics to ref count buffer pool pages 2017 - 07 - 21 07 : 17 : 04 9822 [Note] InnoDB: The InnoDB memory heap is disabled 2017 - 07 - 21 07 : 17 : 04 9822 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2017 - 07 - 21 07 : 17 : 04 9822 [Note] InnoDB: Memory barrier is not used...... [[email protected] mysql]# echo $ ? 0
通过查看运行过程中如果有 2 个 "OK",或者结束后使用 "echo $?" 命令查看为 0,均表示运行正常。
5、拷贝配置文件
- [[email protected] mysql]# cp support - files / my -
- default.cnf / etc / my.cnf cp:是否覆盖"/etc/my.cnf"? y[[email protected] mysql]# vi / etc / my.cnf......datadir = /data/mysql socket = /tmp/mysql.sock......
6、拷贝启动脚本文件
- [[email protected] mysql]# cp support - files / mysql.server / etc / init.d / mysqld[[email protected] mysql]# vi / etc / init.d / mysqld......basedir = /usr/local / mysql datadir = /data/mysql......
7、启动 Mysql
- [[email protected] mysql]# chkconfig --add mysqld[[email protected] mysql]# chkconfig --list | grep mysqld
- 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 如果您想列出 systemd 服务,
- 请执行 'systemctl list - unit - files'。 欲查看对特定 target 启用的服务请执行 'systemctl list - dependencies [target]'。
- mysqld 0 : 关 1 : 关 2 : 开 3 : 开 4 : 开 5 : 开 6 : 关 [[email protected] mysql]# service mysqld start Starting MySQL.Logging to ' / data / mysql / juispan.err'... SUCCESS ! [[email protected] mysql]# netstat - lnpt 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 1096 / sshd tcp 0 0 127.0.0.1 : 25 0.0.0.0 : * LISTEN 1753 / master tcp6 0 0 : ::3306 : ::* LISTEN 10111 / mysqld tcp6 0 0 : ::22 : ::* LISTEN 1096 / sshd tcp6 0 0 : :1 : 25 : ::* LISTEN 1753 / master
如果要关闭 mysqld 服务,可以采用 killall mysqld 或 kill <pid> 命令。
如果 mysql 进程杀不死,说明正在处理的数据量大,如果强行 kill 会丢数据或损坏表。只能慢慢等待。
来源: http://www.bubuko.com/infodetail-2228337.html