美文网首页
LAMP架构介绍、MySQL介绍、MariaDB介绍、MySQL

LAMP架构介绍、MySQL介绍、MariaDB介绍、MySQL

作者: XiaoMing丶 | 来源:发表于2018-11-09 23:21 被阅读0次

目录

一、 LAMP架构介绍
二、 MySQL、MariaDB介绍
三、 MySQL安装

一、 LAMP架构介绍

LAMP是Linux、Apache 、MySQL、PHP的简写,即把Apache、MySQL以及PHP安装在Linux系统上,组成一个环境来运行PHP的脚本语言,通常是网站。

二、 MySQL、MariaDB介绍

  • MySQL是一个关系型数据库,由mysql ab公司开发,mysql在2008年被sun公司收购(10亿刀),2009年sun公司被oracle公司收购(74亿刀)。MySQL官网https://www.mysql.com ,最新版本是5.7GA/8.0DMR。 MySQL5.6变化比较大,5.7性能上有很大提升。
  • Mariadb为MySQL的一个分支,官网https://mariadb.com/,最新版本是10.2。MariaDB主要由SkySQL公司(现更名为MariaDB公司)维护,SkySQL公司由MySQL原作者带领大部分原班人马创立。Mariadb5.5版本对应MySQL的5.5,10.0对应MySQL5.6。

  • Community 社区版本,Enterprise 企业版,GA(Generally Available)指通用版本,在生产环境中用的,DMR(Development Milestone Release)开发里程碑发布版,RC(Release Candidate)发行候选版本,Beta开放测试版本,Alpha内部测试版本。

三、 MySQL安装

  • 下载5.7_64位二进制免编译包
[root@minglinux-01 ~] cd /usr/local/src/       //统一将安装包放在这个目录下
[root@minglinux-01 /usr/local/src] wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
  • 初始化过程
[root@minglinux-01 /usr/local/src] wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz 
[root@minglinux-01 /usr/local/src] mv mysql-5.6.39-linux-glibc2.12-x86_64 /usr/local/mysql
 ##移动文件位置
[root@minglinux-01 /usr/local/src] cd !$
cd /usr/local/mysql
[root@minglinux-01 /usr/local/mysql] ls
bin      data  include  man         README   share      support-files
COPYING  docs  lib      mysql-test  scripts  sql-bench
[root@minglinux-01 /usr/local/mysql] useradd mysql        ##新建mysql用户
[root@minglinux-01 /usr/local/mysql] mkdir -p /data/mysql    ##数据库文件存放路径
[root@minglinux-01 /usr/local/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-Module-Install,下面命令安装该包

[root@minglinux-01 /usr/local/mysql] yum install -y perl-Module-Install

[root@minglinux-01 /usr/local/mysql] ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql  ####再次执行这个脚本对数据库初始化
[root@minglinux-01 /usr/local/mysql] echo $?
0
[root@minglinux-01 /usr/local/mysql] ls /data/mysql/
ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  test  ##、data/mysql目录下生成了一些文件和目录,说明脚本执行正确

  • 配置 MySQL
[root@minglinux-01 /usr/local/mysql] cp support-files/my-default.cnf  /etc/my.cnf 
cp:是否覆盖"/etc/my.cnf"? y   //覆盖配置文件
  • 打开配置文件,把配置文件改成如下内容:
[mysqld]
# 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
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin = minglinux
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql      //basedir是MySQL包所在的路径
datadir = /data/mysql          //datadir是定义的存放数据的地方,默认错误日志也会记录在这个目录下面
port = 3306             //port定义MySQL服务监听的端口
server_id = 128        //server_id定义该MySQL服务的ID号
socket = /tmp/mysql.sock          //socket定义MySQL服务监听
的套接字地址
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
  • 复制启动脚本文件并修改其属性(启动脚本文件仅修改basedir=/usr/local/mysql和datadir=/data/mysql):
[root@minglinux-01 /usr/local/mysql] cp support-files/mysql.server /etc/init.d/mysqld 
[root@minglinux-01 /usr/local/mysql] chmod 755 /etc/init.d/mysqld 
[root@minglinux-01 /usr/local/mysql] vim /etc/init.d/mysqld
#修改如下内容
 46 basedir=/usr/local/mysql
 47 datadir=/data/mysql

  • 把启动脚本加入系统服务项,设定开机启动并启动MySQL:
[root@minglinux-01 /usr/local/mysql] chkconfig --add mysqld //把mysqld服务加入到系统服务
[root@minglinux-01 /usr/local/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:关
[root@minglinux-01 /usr/local/mysql] chkconfig mysqld on //使其开机就启动
[root@minglinux-01 /usr/local/mysql] service mysqld start   //启动mysql服务
Starting MySQL.Logging to '/data/mysql/minglinux-02.err'.
. SUCCESS! 
  • 通过查看进程和监听端口方式检查MySQL是否启动:
[root@minglinux-01 /usr/local/mysql] ps aux |grep mysql
root       4629  0.0  0.0  11816  1608 pts/0    S    07:13   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/minglinux-02.pid
mysql      4866  1.5 24.3 1302728 453332 pts/0  Sl   07:13   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysq --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=minglinux-01.err --pid-file=/data/mysql/minglinux-01.pid --socket=/tmp/mysql.sock --port=3306
root       4892  0.0  0.0 112720   984 pts/0    S+   07:14   0:00 grep --color=auto mysql
[root@minglinux-01 /usr/local/mysql] netstat -lnp |grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      4866/mysqld   
  • 还有另一种命令行启动方法
    /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
[root@minglinux-02 /usr/local/mysql] service mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@minglinux-02 /usr/local/mysql] !ps
ps aux |grep mysql
root       4943  0.0  0.0 112720   984 pts/0    S+   07:47   0:00 grep --color=auto mysql
[root@minglinux-02 /usr/local/mysql] /usr/local/mysql/bin/mysqld_safe  --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
[1] 4945
[root@minglinux-02 /usr/local/mysql] 181110 07:47:25 mysqld_safe Logging to '/data/mysql/minglinux-02.err'.
181110 07:47:25 mysqld_safe Starting mysqld daemon with databases from /data/mysql
^C
[root@minglinux-02 /usr/local/mysql] ps aux |grep mysql
root       4945  0.1  0.0 113308  1616 pts/0    S    07:47   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --usermysql --datadir=/data/mysql
mysql      5171  2.2 24.2 1302728 452676 pts/0  Sl   07:47   0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=minglinux-02.err --pid-file=minglinux-02.pid --socket=/tmp/mysql.sock --port=3306
root       5194  0.0  0.0 112720   980 pts/0    S+   07:47   0:00 grep --color=auto mysql
  • 命令行的开启只能用kill命令来进行关闭服务,用killall更安全,killall会先停止写读操作,然后写读完成才将进程杀死。
    使用yum install psmisc安装killall。
[root@minglinux-02 /usr/local/mysql] !ps
ps aux |grep mysql
root       4945  0.0  0.0 113308  1616 pts/0    S    07:47   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --usermysql --datadir=/data/mysql
mysql      5171  0.3 24.3 1302728 454708 pts/0  Sl   07:47   0:02 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=minglinux-02.err --pid-file=minglinux-02.pid --socket=/tmp/mysql.sock --port=3306
root       5227  0.0  0.0 112724   980 pts/0    S+   07:57   0:00 grep --color=auto mysql
[root@minglinux-02 /usr/local/mysql] killall mysqld
[root@minglinux-02 /usr/local/mysql] 181110 07:58:20 mysqld_safe mysqld from pid file /data/mysql/minglinux-02.pid ended
^C
[1]+  完成                  /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
[root@minglinux-02 /usr/local/mysql] ps aux |grep mysql
root       5233  0.0  0.0 112720   984 pts/0    S+   08:01   0:00 grep --color=auto mysql
扩展

mysql5.5源码编译安装

http://www.aminglinux.com/bbs/thread-1059-1-1.html

mysql5.7二进制包安装(变化较大)

http://www.apelearn.com/bbs/thread-10105-1-1.html

相关文章

网友评论

      本文标题:LAMP架构介绍、MySQL介绍、MariaDB介绍、MySQL

      本文链接:https://www.haomeiwen.com/subject/slegxqtx.html