LAMP架构介绍与MySQL二进制包安装

LAMP架构介绍

  • Linux + Apache(httpd) + MySQL + PHP
  • PHP网站(Google、淘宝、百度)
  • 三个角色可以在一台机器、也可以分开(httpd和PHP要在一起)

httpd、PHP、MySQL工作关系图

PHP去MySQL中读取数据是个“动态”请求过程。

MySQL/Mariadb介绍

  • MySQL是一个关系型数据库,由mysql ab公司开发,mysql在2008年被sun公司收购(10亿美金),2009年sun公司被oracle公司收购(74亿美金)
  • MySQL官网https://www.mysql.com
  • MySQL5.6变化比较大,5.7性能上有很大提升
  • Mariadb为MySQL的一个分支,官网https://mariadb.com
  • Mariadb主要由SkySQL公司(现更名为MariaDB公司)维护,SkySQL公司由MySQL原作者带领大部分原班人马创立。
  • Community 社区版本,Enterprise 企业版,GA(Generally Available) 通用版本,在生产环境中用的,DMR(Development Milestone Release) 开发里程碑发布版,RC(Release Candidate) 发行候选版本,Beta开发测试版,Alpha内部测试版本

安装MySQL

  • MySQL的几个常用按转包: rpm、源码、二进制免编译

用二进制免编译安装(对性能没有较高的要求的情况下)Mysql5.7

[root@test-a ~]# uname -a  # 查看系统位数
Linux test-a 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

[root@test-a ~]# cd /usr/local/src/  
# 下载二进制包
[root@test-a src]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz  
[root@test-a src]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 把解压后的目录重命名mysql后移动到/usr/local下
[root@test-a src]# mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
[root@test-a mysql]# useradd mysql # 创建mysql用户
[root@test-a mysql]# mkdir /data/  # 为mysql创建数据存储目录  
[root@test-a mysql]# ./bin/mysql_install_db # 需要指定数据目录和建议使用mysqld --initialize来初始化数据库
2018-11-12 06:33:14 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-11-12 06:33:14 [ERROR]   The data directory needs to be specified.

[root@test-a mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql
2018-11-11T22:37:03.945687Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-11T22:37:06.436762Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-11T22:37:06.779631Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-11T22:37:06.842918Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 519df254-e602-11e8-91f0-000c29b95699.
2018-11-11T22:37:06.845661Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-11T22:37:06.847683Z 1 [Note] A temporary password is generated for root@localhost: (a1ckckbsd2A
# 数据库初始化完成

[root@test-a mysql]# cp support-files/mysql.server /etc/init.d/mysqld # 拷贝mysql启动脚本到/etc/init.d/下并重命名为mysqld
[root@test-a mysql]# vi /etc/init.d/mysqld
#更改两行配置如下
# basedir=/usr/loca/mysql
# datadir=/data/mysql
[root@test-a mysql]# chkconfig --add mysqld  # 设置mysqld以后启动为跟随系统自启动
[root@test-a mysql]# chkconfig --list

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]'.

iprdump         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprinit         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprupdate       0:off   1:off   2:on    3:on    4:on    5:on    6:off
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

# 新建mysql 配置文件/etc/my.cnf(有则清空),添加如下内容
[mysql]
socket          = /usr/local/mysql/mysql.sock
# The MySQL server
[mysqld]
port            = 3306
socket          = /usr/local/mysql/mysql.sock
#skip-grant-tables
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/db.err
pid-file=/usr/local/mysql/mysqld.pid
character-set-server = utf8

[root@test-a lib]#  service mysqld start #启动报错,添加对应的文件db.err
Starting MySQL.2018-11-11T23:24:48.581799Z mysqld_safe error: log-error set to '/usr/local/mysql/db.err', 't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/mysqld.pid).
 
 [root@test-a lib]# touch db.err
[root@test-a lib]# chown mysql:mysql db.err

[root@test-a mysql]#  service mysqld start # 再次失败
Starting MySQL................................................................... ERROR! The server quit wPID file (/usr/local/mysql/mysqld.pid).

#是因为mysql目录的文件需要属于mysql用户
[root@test-a mysql]# chown mysql:mysql -R .
[root@test-a mysql]#  service mysqld start
Starting MySQL......... SUCCESS!

#另外一种启动方式,其中--defaults-file必须紧接着命令后面,可以没有,默认/etc/my.cnf
[root@test-a mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &

# 停止服务
[root@test-a mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS!
# 另外一种方法
[root@test-a mysql]# killall mysqld # 不要使用kill -9 pid,有可能丢数据

猜你喜欢

转载自my.oschina.net/u/996931/blog/2874804
今日推荐