LAMP 架构
1.lamp 包含什么
httpdPHPMySQL 三者如何工作
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
来源: http://www.bubuko.com/infodetail-2508539.html