美文网首页我爱编程
LAMP架构介绍、MySQL安装

LAMP架构介绍、MySQL安装

作者: 强出头 | 来源:发表于2018-04-09 22:24 被阅读0次

MySQL安装

MySQL安装

没有特殊要求就用二进制免编译包
存放包的目录 /usr/local/src/

[root@wsl-001 src]# uname -a
Linux wsl-001 3.10.0-693.11.6.el7.x86_64 #1 SMP Thu Jan 4 01:06:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@wsl-001 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
--2018-04-09 20:26:25--  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 2.45MB/s 用时 2m 14s 

2018-04-09 20:28:41 (2.25 MB/s) - 已保存 “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz” [316320366/316320366])

[root@wsl-001 src]# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz 
[root@wsl-001 src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
[root@wsl-001 src]# cd /usr/local/mysql/
[root@wsl-001 mysql]# useradd mysql
[root@wsl-001 mysql]# mkdir /data/
[root@wsl-001 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相关包,-i忽略大小写
不确定哪一个就全部装上

[root@wsl-001 mysql]# yum list |grep perl |grep -i dumper
perl-Data-Dumper.x86_64                   2.145-3.el7                  base     
perl-Data-Dumper-Concise.noarch           2.020-6.el7                  epel     
perl-Data-Dumper-Names.noarch             0.03-17.el7                  epel     
perl-XML-Dumper.noarch                    0.81-17.el7                  base     
[root@wsl-001 mysql]# yum install -y perl-Data-Dumper
[root@wsl-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
[root@wsl-001 mysql]# echo $?
0
[root@wsl-001 mysql]# ls
bin      data  include  man     mysql-test  scripts  sql-bench
COPYING  docs  lib      my.cnf  README      share    support-files
[root@wsl-001 mysql]# ls support-files/my-default.cnf 
support-files/my-default.cnf
[root@wsl-001 mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? ^C
[root@wsl-001 mysql]# ls /etc/my.cnf
/etc/my.cnf
[root@wsl-001 mysql]# rpm -qf /etc/my.cnf
mariadb-libs-5.5.56-2.el7.x86_64
[root@wsl-001 mysql]# vim /etc/my.cnf
修改默认配置文件
[root@wsl-001 mysql]# ls support-files/
binary-configure  my-default.cnf       mysql-log-rotate
magic             mysqld_multi.server  mysql.server
[root@wsl-001 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@wsl-001 mysql]# vim /etc/init.d/mysqld 

basedir=/usr/local/mysql
datadir=/data/mysql

[root@wsl-001 mysql]# ls -l /etc/init.d/mysqld 
-rwxr-xr-x 1 root root 10592 4月   9 21:23 /etc/init.d/mysqld
[root@wsl-001 mysql]# chkconfig --add mysqld  (开机启动)
[root@wsl-001 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@wsl-001 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/wsl-001.err'.
. SUCCESS! 
[root@wsl-001 mysql]# ps aux |grep mysql
root       3476  0.0  0.0 113264  1624 pts/0    S    21:34   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/wsl-001.pid
mysql      3613  5.4 24.0 1300776 449544 pts/0  Sl   21:34   0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/wsl-001.err --pid-file=/data/mysql/wsl-001.pid --socket=/tmp/mysql.sock
root       3639  0.0  0.0 112676   984 pts/0    S+   21:34   0:00 grep --color=auto mysql
[root@wsl-001 mysql]# netstat -lntp
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      874/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1093/master         
tcp        0      0 172.16.79.140:8730      0.0.0.0:*               LISTEN      1655/rsync          
tcp6       0      0 :::3306                 :::*                    LISTEN      3613/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      874/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1093/master 

当没有启动脚本或者没有模板在/etc/里面时启动
killall会等数据写完才会杀死进程

[root@wsl-001 mysql]# /etc/init.d/mysqld stop
Shutting down MySQL..180409 21:39:40 mysqld_safe mysqld from pid file /data/mysql/wsl-001.pid ended
 SUCCESS! 
[1]+  完成                  /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
[root@wsl-001 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
[1] 4110
[root@wsl-001 mysql]# 180409 21:40:18 mysqld_safe Logging to '/data/mysql/wsl-001.err'.
180409 21:40:18 mysqld_safe Starting mysqld daemon with databases from /data/mysql

[root@wsl-001 mysql]# !ps
ps aux |grep mysql
root       4110  0.2  0.0 113260  1592 pts/0    S    21:40   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
mysql      4235  5.1 24.0 1300776 449520 pts/0  Sl   21:40   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=/data/mysql/wsl-001.err --pid-file=/data/mysql/wsl-001.pid --socket=/tmp/mysql.sock
root       4258  0.0  0.0 112676   984 pts/0    R+   21:40   0:00 grep --color=auto mysql
[root@wsl-001 mysql]# killall mysqld
[root@wsl-001 mysql]# 180409 21:42:03 mysqld_safe mysqld from pid file /data/mysql/wsl-001.pid ended

扩展
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安装

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