11.1 LAMP架构介绍
11.2 MySQL、MariaDB介绍
11.3/11.4/11.5 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
==================================================================================================================================================================================================================
Last login: Mon Feb 26 20:46:31 2018
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# ls
httpd-2.2.34 httpd-2.2.34.tar.gz
[root@localhost src]# uname -a
Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
--2018-02-26 22:01:36-- 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.40MB/s 用时 2m 6s
2018-02-26 22:03:43 (2.39 MB/s) - 已保存 “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz” [316320366/316320366])
[root@localhost src]# ls
httpd-2.2.34 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
httpd-2.2.34.tar.gz
[root@localhost src]# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
mysql-5.6.36-linux-glibc2.5-x86_64/mysql-test/README
mysql-5.6.36-linux-glibc2.5-x86_64/mysql-test/purify.supp
mysql-5.6.36-linux-glibc2.5-x86_64/mysql-test/collections/README
mysql-5.6.36-linux-glibc2.5-x86_64/mysql-test/collections/default.weekly-valgrind
mysql-5.6.36-linux-glibc2.5-x86_64/mysql-test/collections/disabled-gtid-on.list
====================================解压部分删除(太多了~)==================================================================================================================================================================================================================
[root@localhost src]# http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
-bash: http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz: 没有那个文件或目录
[root@localhost src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
[root@localhost src]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin data include man README share support-files
COPYING docs lib mysql-test scripts sql-bench
[root@localhost mysql]# ./scripts/mysql_install_db ^C
[root@localhost mysql]# useradd mysql
[root@localhost mysql]# mkdir /data
[root@localhost mysql]# ls /data/
[root@localhost 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
[root@localhost mysql]# yum install -y perl-XML-Dumper
已加载插件:fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base | 3.6 kB 00:00
epel/x86_64/metalink | 6.3 kB 00:00
epel | 4.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/3): epel/x86_64/updateinfo | 892 kB 00:00
(2/3): epel/x86_64/primary_db | 6.2 MB 00:00
(3/3): updates/7/x86_64/primary_db | 6.0 MB 00:01
Determining fastest mirrors
* epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 perl-XML-Dumper.noarch.0.0.81-17.el7 将被 安装
--> 正在处理依赖关系 perl(XML::Parser),它被软件包 perl-XML-Dumper-0.81-17.el7.noarch 需要
--> 正在检查事务
---> 软件包 perl-XML-Parser.x86_64.0.2.41-10.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================
Package 架构 版本 源 大小
===========================================================================
正在安装:
perl-XML-Dumper noarch 0.81-17.el7 base 25 k
为依赖而安装:
perl-XML-Parser x86_64 2.41-10.el7 base 223 k
事务概要
===========================================================================
安装 1 软件包 (+1 依赖软件包)
总下载量:247 k
安装大小:669 k
Downloading packages:
(1/2): perl-XML-Dumper-0.81-17.el7.noarch.rpm | 25 kB 00:00
(2/2): perl-XML-Parser-2.41-10.el7.x86_64.rpm | 223 kB 00:00
---------------------------------------------------------------------------
总计 840 kB/s | 247 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : perl-XML-Parser-2.41-10.el7.x86_64 1/2
正在安装 : perl-XML-Dumper-0.81-17.el7.noarch 2/2
验证中 : perl-XML-Dumper-0.81-17.el7.noarch 1/2
验证中 : perl-XML-Parser-2.41-10.el7.x86_64 2/2
已安装:
perl-XML-Dumper.noarch 0:0.81-17.el7
作为依赖被安装:
perl-XML-Parser.x86_64 0:2.41-10.el7
完毕!
[root@localhost 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
[root@localhost 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 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================
Package 架构 版本 源 大小
===========================================================================
正在安装:
perl-Data-Dumper x86_64 2.145-3.el7 base 47 k
事务概要
===========================================================================
安装 1 软件包
总下载量:47 k
安装大小:97 k
Downloading packages:
perl-Data-Dumper-2.145-3.el7.x86_64.rpm | 47 kB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : perl-Data-Dumper-2.145-3.el7.x86_64 1/1
验证中 : perl-Data-Dumper-2.145-3.el7.x86_64 1/1
已安装:
perl-Data-Dumper.x86_64 0:2.145-3.el7
完毕!
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...2018-02-26 22:17:38 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:17:38 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-02-26 22:17:38 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 3050 ...
2018-02-26 22:17:38 3050 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-02-26 22:17:38 3050 [Note] InnoDB: The InnoDB memory heap is disabled
2018-02-26 22:17:38 3050 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-02-26 22:17:38 3050 [Note] InnoDB: Memory barrier is not used
2018-02-26 22:17:38 3050 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-02-26 22:17:38 3050 [Note] InnoDB: Using Linux native AIO
2018-02-26 22:17:38 3050 [Note] InnoDB: Using CPU crc32 instructions
2018-02-26 22:17:38 3050 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-02-26 22:17:38 3050 [Note] InnoDB: Completed initialization of buffer pool
2018-02-26 22:17:38 3050 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-02-26 22:17:38 3050 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-02-26 22:17:38 3050 [Note] InnoDB: Database physically writes the file full: wait...
2018-02-26 22:17:38 3050 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-02-26 22:17:38 3050 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-02-26 22:17:39 3050 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-02-26 22:17:39 3050 [Warning] InnoDB: New log files created, LSN=45781
2018-02-26 22:17:39 3050 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-02-26 22:17:39 3050 [Note] InnoDB: Doublewrite buffer created
2018-02-26 22:17:39 3050 [Note] InnoDB: 128 rollback segment(s) are active.
2018-02-26 22:17:39 3050 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-02-26 22:17:39 3050 [Note] InnoDB: Foreign key constraint system tables created
2018-02-26 22:17:39 3050 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-02-26 22:17:39 3050 [Note] InnoDB: Tablespace and datafile system tables created.
2018-02-26 22:17:39 3050 [Note] InnoDB: Waiting for purge to start
2018-02-26 22:17:39 3050 [Note] InnoDB: 5.6.36 started; log sequence number 0
2018-02-26 22:17:39 3050 [Note] Binlog end
2018-02-26 22:17:39 3050 [Note] InnoDB: FTS optimize thread exiting.
2018-02-26 22:17:39 3050 [Note] InnoDB: Starting shutdown...
2018-02-26 22:17:41 3050 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2018-02-26 22:17:41 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:17:41 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-02-26 22:17:41 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 3072 ...
2018-02-26 22:17:41 3072 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-02-26 22:17:41 3072 [Note] InnoDB: The InnoDB memory heap is disabled
2018-02-26 22:17:41 3072 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-02-26 22:17:41 3072 [Note] InnoDB: Memory barrier is not used
2018-02-26 22:17:41 3072 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-02-26 22:17:41 3072 [Note] InnoDB: Using Linux native AIO
2018-02-26 22:17:41 3072 [Note] InnoDB: Using CPU crc32 instructions
2018-02-26 22:17:41 3072 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-02-26 22:17:41 3072 [Note] InnoDB: Completed initialization of buffer pool
2018-02-26 22:17:41 3072 [Note] InnoDB: Highest supported file format is Barracuda.
2018-02-26 22:17:41 3072 [Note] InnoDB: 128 rollback segment(s) are active.
2018-02-26 22:17:41 3072 [Note] InnoDB: Waiting for purge to start
2018-02-26 22:17:41 3072 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2018-02-26 22:17:41 3072 [Note] Binlog end
2018-02-26 22:17:41 3072 [Note] InnoDB: FTS optimize thread exiting.
2018-02-26 22:17:41 3072 [Note] InnoDB: Starting shutdown...
2018-02-26 22:17:43 3072 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
./bin/mysqladmin -u root password ‘new-password‘
./bin/mysqladmin -u root -h localhost.localdomain password ‘new-password‘
Alternatively you can run:
./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
[root@localhost mysql]# echo $?
0
[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf^C
[root@localhost mysql]# vim /etc/my.cnf
[root@localhost mysql]# ls
bin data include man mysql-test scripts sql-bench
COPYING docs lib my.cnf README share support-files
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# vi /etc/init.d/mysqld
[root@localhost mysql]# ls -l /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10592 2月 26 22:30 /etc/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost 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@localhost mysql]# service mysqld start
Starting MySQL.Logging to ‘/data/mysql/localhost.localdomain.err‘.
.. SUCCESS!
[root@localhost mysql]# ps aux |grep mysql
root 3358 0.0 0.0 11776 1584 pts/0 S 22:33 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql 3495 5.6 10.8 1300792 453080 pts/0 Sl 22:33 0:02 /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/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock
root 3523 0.0 0.0 112676 976 pts/0 S+ 22:34 0:00 grep --color=auto mysql
[root@localhost 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 1091/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1638/master
tcp6 0 0 :::3306 :::* LISTEN 3495/mysqld
tcp6 0 0 :::22 :::* LISTEN 1091/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1638/master
[root@localhost mysql]# killall 3358
-bash: killall: 未找到命令
[root@localhost mysql]# killall mysql
-bash: killall: 未找到命令
[root@localhost mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost 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 1091/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1638/master
tcp6 0 0 :::22 :::* LISTEN 1091/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1638/master
[root@localhost mysql]#