LAMP架构介绍
LAMP指的L(linux)、A(Apache)、M(mysql)、P(php);apache+php需要在一台主机,mysql可以分开也可以在同一台主机上运行。
工作模式如下:
静态文件:图片、文档,不用通过加载mysql去取数据
动态文件:js等通过php模块调用mysql,再通过apache展示来实现的动态资源
MySQL,MariaDB介绍
mysql:关系型数据库,由sun公司研发,后被oracle公司收购;
其版本:
community 社区版;enterprise 企业版;GA(generally available) 通用版,在生产环境中使用;DMR(development milestone release) 开发里程碑版本;RC(release candidate) 发行候选版本;Beta 公测版本;Alpha 内部测试版本。
MariaDB:和mysql基本一致,是mysql的一个分支。
MySQL安装
常用的安装包:
rpm包(rpm -ivh 安装)
源码包(源代码编译安装,耗时比较久,一般也得20多分钟)
二进制免编译包(已经编译好的,拿来就可以直接使用,简单快速安装)
1、下载安装包(二进制免编译包):
[root@centos7 package]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
2、解压
[root@centos7 package]# tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
3、[root@centos7 package]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
4、创建mysql、data目录
[root@centos7 mysql]# useradd mysql
[root@centos7 mysql]# mkdir /data/
5、安装相应的软件包
[root@centos7 mysql]# yum install -y perl-Data-Dumper libaio* libaio-dev*
6、初始化
[root@centos7 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
7、验证是否正确
[root@centos7 mysql]# echo $?
0
8、拷贝配置文件到/etc
[root@centos7 mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
9、新增datadir、socket:
[root@centos7 mysql]# cat /etc/my.cnf
# 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]
datadir=/data/mysql
socket=/tmp/mysql.sock
# 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
10、启动脚本:
[root@centos7 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@centos7 mysql]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
11、[root@centos7 mysql]# chmod 755 /etc/init.d/mysqld
12、
[root@centos7 mysql]# chkconfig --add mysqld
[root@centos7 mysql]# chkconfig --list| grep mysqld
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
13、启动
[root@centos7 mysql]# /etc/init.d/mysqld start
14、[root@centos7 mysql]# netstat -nutlp| grep mysqld
tcp6 0 0 :::3306 :::* LISTEN 18112/mysqld
14、错误信息:
[root@centos7 ~]# killall
-bash: killall: command not found
解决:[root@centos7 ~]# yum install psmisc -y
15、[root@centos7 ~]# killall mysqld
16、没有启动脚本时,如下启动:
[root@centos7 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
17、[root@centos7 ~]# ps aux|grep mysql