CentOS7安装PHP开发环境4-源码安装MySQL5.6

软件版本
OS:CentOS 7
MySQL:5.6.44

安装

下载mysql 5.6.44
下载页面:https://dev.mysql.com/downloads/mysql/5.6.html#downloads
下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40.tar.gz
下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.44.tar.gz
在这里插入图片描述

安装MySQL需要的依赖包和编译软件

# yum install ncurses-devel libaio-devel cmake -y

检测是否已安装

首先检查是否已经安装过mysql:

# rpm -qa | grep mysql

有的话就卸载掉以前安装的mysql:

# rpm -e --nodeps xxx(xxx是搜索结果)

并删除所有的相关文件:/etc/my.cnf(可用有 mv /etc/my.cnf /etc/my.cnf.back)

建立MySQL用户账户

创建mysql用户(但是不能使用mysql账号登陆系统)(要修改成如下方式)
检查系统是否已经有mysql用户,

# cat /etc/passwd | grep mysql
# cat /etc/group | grep mysql

如果没有则创建

# groupadd mysql
# useradd -s /sbin/nologin -g mysql mysql

或者使用如下命令创建

# useradd -s /sbin/nologin -M mysql  #<==默认会创建和mysql用户同名的组。

解压并配置MySQL,命令及操作

# tar zxvf mysql-5.6.44.tar.gz
# cd mysql-5.6.44.tar.gz
# cmake -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.44 \
-DMYSQL_DATADIR=/application/mysql-5.6.44/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.6.44/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0

编译并安装MySQL

如果是多核CPU,则可指定make -j CPU核数,加快编译速度。

# make
# make install

为MySQL安装路径设置不带版本号的软连接

为MySQL安装路径设置不带版本号的软连接/application/mysql,操作命令如下

# ln -s /application/mysql-5.6.44 /application/mysql

创建MySQL数据库配置文件并对数据库目录授权

MySQL 5.5及老版数据库默认为用户提供了多个配置文件模板,但是MySQL 5.6的support-files目录下已经没有配置文件模板了。

# ll support-files/*.cnf
-rw-r--r--. 1 mysql mysql 1126 Jul 21 12:02 support-files/my-default.cnf
# mv /etc/my.cnf /etc/my.cnf.bak

提示:在CentOS 6.6版操作系统最小化安装完成之后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
在启动MySQL服务时,会按照一定的顺序搜索my.cnf,先在/etc目录下找,若找不到则搜索"$basedir/my.cnf",本例依旧选择大家熟悉的/etc/路径!

# cp support-files/my-default.cnf /etc/my.c

提示:此行操作可以省略,在下文初始化mysql时会自动生成my.cnf模板文件,如果已经执行了上述命令,则初始化后会生成my-new.cnf文件,my.cnf和my-new.cnf除了注释以外是一致的。

# chown -R mysql.mysql /application/mysql/

#<==授权mysql用户管理mysql的安装目录,此步不做会导致启动服务错误。

MySQL相关命令加入全局路径的配置

# vim /etc/profile
PATH=/application/mysql/bin:$PATH

Esc :wq

# source /etc/profile

单实例配置

初始化MySQL单实例的数据库

执行初始化配置脚本,创建系统自带的数据库和表

[root@www mysql]# /application/mysql/scripts/mysql_install_db \
--basedir=/application/mysql/ \
--datadir=/application/mysql/data \
--user=mysql

提示: --basedir=/application/mysql/为MySQL的安装路径, --datadir为数据文件目录。另外,需要注意mysql_install_db和MySQL 5.1的路径不同,MySQL 5.1在MySQL bin路径下。

初始化的操作过程

[root@www mysql]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql
WARNING: The host 'www' could not be looked up with /application/mysql//bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !

Installing MySQL system tables...2019-07-23 12:23:28 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-23 12:23:28 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-07-23 12:23:28 0 [Note] /application/mysql//bin/mysqld (mysqld 5.6.44) starting as process 4517 ...
2019-07-23 12:23:28 4517 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-07-23 12:23:28 4517 [Note] InnoDB: The InnoDB memory heap is disabled
2019-07-23 12:23:28 4517 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-07-23 12:23:28 4517 [Note] InnoDB: Memory barrier is not used
2019-07-23 12:23:28 4517 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-07-23 12:23:28 4517 [Note] InnoDB: Using Linux native AIO
2019-07-23 12:23:28 4517 [Note] InnoDB: Using CPU crc32 instructions
2019-07-23 12:23:28 4517 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-07-23 12:23:28 4517 [Note] InnoDB: Completed initialization of buffer pool
2019-07-23 12:23:28 4517 [Note] InnoDB: Highest supported file format is Barracuda.
2019-07-23 12:23:29 4517 [Note] InnoDB: 128 rollback segment(s) are active.
2019-07-23 12:23:29 4517 [Note] InnoDB: Waiting for purge to start
2019-07-23 12:23:29 4517 [Note] InnoDB: 5.6.44 started; log sequence number 1600617
2019-07-23 12:23:29 4517 [Note] Binlog end
2019-07-23 12:23:29 4517 [Note] InnoDB: FTS optimize thread exiting.
2019-07-23 12:23:29 4517 [Note] InnoDB: Starting shutdown...
2019-07-23 12:23:31 4517 [Note] InnoDB: Shutdown completed; log sequence number 1625997
OK

Filling help tables...2019-07-23 12:23:31 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-23 12:23:31 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-07-23 12:23:31 0 [Note] /application/mysql//bin/mysqld (mysqld 5.6.44) starting as process 4541 ...
2019-07-23 12:23:31 4541 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-07-23 12:23:31 4541 [Note] InnoDB: The InnoDB memory heap is disabled
2019-07-23 12:23:31 4541 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-07-23 12:23:31 4541 [Note] InnoDB: Memory barrier is not used
2019-07-23 12:23:31 4541 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-07-23 12:23:31 4541 [Note] InnoDB: Using Linux native AIO
2019-07-23 12:23:31 4541 [Note] InnoDB: Using CPU crc32 instructions
2019-07-23 12:23:31 4541 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-07-23 12:23:31 4541 [Note] InnoDB: Completed initialization of buffer pool
2019-07-23 12:23:31 4541 [Note] InnoDB: Highest supported file format is Barracuda.
2019-07-23 12:23:31 4541 [Note] InnoDB: 128 rollback segment(s) are active.
2019-07-23 12:23:31 4541 [Note] InnoDB: Waiting for purge to start
2019-07-23 12:23:31 4541 [Note] InnoDB: 5.6.44 started; log sequence number 1625997
2019-07-23 12:23:31 4541 [Note] Binlog end
2019-07-23 12:23:31 4541 [Note] InnoDB: FTS optimize thread exiting.
2019-07-23 12:23:31 4541 [Note] InnoDB: Starting shutdown...
2019-07-23 12:23:33 4541 [Note] InnoDB: Shutdown completed; log sequence number 1626007
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:

  /application/mysql//bin/mysqladmin -u root password 'new-password'
  /application/mysql//bin/mysqladmin -u root -h www password 'new-password'

Alternatively you can run:

  /application/mysql//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 . ; /application/mysql//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 /application/mysql//my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

初始化mysql数据库文件,会有很多信息提示,如果没有ERROR级别的错误,有两个OK的字样,则表示初始化成功,否则就要解决初始化的问题。

配置并启动MySQL数据库

方式一
启动MySQL

[root@www mysql]# /application/mysql/support-files/mysql.server start
Starting MySQL. SUCCESS!

关闭MySQL

[root@www mysql]# /application/mysql/support-files/mysql.server stop
Shutting down MySQL.. SUCCESS!

方式二
启动MySQL

[root@www mysql]# /application/mysql/bin/mysqld_safe --user=mysql &

关闭MySQL

[root@www mysql]# /application/mysql/support-files/mysql.server stop

特别提示:这里有一个大坑,就是数据库可能会无法启动,报错信息如下:

[root@www mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/application/mysql-5.6.44/data/oldboy.err'.
180510 00:21:04 mysqld_safe Directory '/application/mysql-5.6.44/tmp' for UNIX socket file don't exists.
 ERROR! The server quit without updating PID file (/application/mysql-5.6.44/data/oldboy.pid).

提示:/application/mysql-5.6.44/tmp目录不存在,5.6.34前的早期版本没事。
解决办法:

# mkdir -p /application/mysql-5.6.44/tmp

#<==编译时指定的socket路径。

# chown -R mysql.mysql /application/mysql/
# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

提示:禁止使用kill -9、killall -9等命令强制杀死数据库,这会引起数据库无法启动等故障发生。企业中曾发生过的血的教训案例请看 http://oldboy.blog.51cto.com/2561410/1431161

设置MySQL开机自启动

检查MySQL数据库是否启动

[root@www mysql]# netstat -lntup|grep mysql
tcp      0      0 :::3306      :::*      LISTEN      4797/mysqld

如果发现3306端口没起来,则请使用tail-100/application/mysql/data/机器名.err 检查日志报错进行调试。

设置MySQL开机自启动

# mv /etc/my.cnf /etc/my.cnf.bak
# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list mysqld
mysqld               0:off       1:off      2:on      3:on      4:on      5:on      6:off

chkconfig mysqld on #设置开机启动
chkconfig mysqld off #禁止开机启动
service mysqld start #启动MySQL服务
service mysqld stop #关闭MySQL服务
service mysqld restart #重启MySQL
netstat -lntup|grep mysql

此外,将启动命令/etc/init.d/mysqld start放到/etc/rc.local里面也可以实现开机自启动。
若MySQL安装及使用出现故障,则可根据下面的分析思路进行检查。

  • 细看所有步骤执行命令返回的屏幕输出,不要忽略关键的输出内容。
  • 查看mysql错误日志/application/mysql/data/机器名.err。
  • 辅助查看系统日志/var/log/messages。
  • 如果是MySQL关联了其他服务,则还要同时查看相关服务的日志。
  • 仔细阅读,重新查看所有操作的步骤是否正确,书写的命令及字符是否都正确。

重置root用户密码

MySQL 5.6管理员的账号root密码默认为空,极不安全,可以通过mysqladmin命令为mysql不同实例的数据库设置独立的密码。

# /application/mysql/bin/mysqladmin -u root password 'root'
Warning: Using a password on the command line interface can be insecure.

终端登录

# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.44 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

也可以执行mysql_secure_installation命令交互式地设置系统的用户密码

多实例配置

多实例配置完成后,MySQL双实例的目录信息及文件注释说明:

# tree /data
/data
|-- 3306
|   |-- data   #<==3306实例的数据文件。
|   |-- my.cnf #<==3306实例的配置文件。
|   `-- mysql  #<==3306实例的启动文件。
`-- 3307
    |-- data   #<==3307实例的数据文件。
    |-- my.cnf #<==3307实例的配置文件。
    `-- mysql  #<==3307实例的启动文件。
4 directories, 4 files

提示:这里的配置文件my.cnf、启动程序mysql都是独立的文件,数据文件data目录也是独立的。

创建MySQL多实例的数据文件目录

以"/data"目录作为MySQL多实例总的根目录,然后规划不同的数字(即MySQL实例端口号)作为“/data”下面的二级目录;不同的二级目录对应的数字就作为MySQL实例的端口号,以区别不同的实例;数字对应的二级目录下包含MySQL的数据文件、配置文件以及启动文件等。

下面以配置3306、3307两个实例为例进行讲解。创建MySQL多实例的目录如下:

# mkdir -p /data/{3306,3307}/data

创建MySQL多实例的配置文件

如果配置多实例,则其与单实例会有所不同。为了让MySQL多实例之间彼此独立,需要为每一个实例建立一个my.cnf配置文件和一个启动文件mysql,让它们分别对应自己的数据文件目录data。

# touch /data/3306/my.cnf
# touch /data/3307/my.cnf

不同的实例需要添加的my.cnf内容也会有区别。

MySQL 3306实例

# cat /data/3306/my.cnf 
[client]								#<==客户端模块
port		=3306						#<==客户端端口
socket		=/data/3306/mysql.sock

[mysqld]								#<==服务端模块
user		=mysql						#<==用户
port		=3306						#<==端口
socket		=/data/3306/mysql.sock		#<==socket路径
basedir		=/application/mysql			#<==安装路径
datadir		=/data/3306/data			#<==数据文件
log-bin		=/data/3306/mysql-bin		#<==二进制日志
server-id	=6

[mysqld_safe]							#<==启动服务模块
log-error	=/data/3306/www_3306.err	#<==错误日志
pid-file	=/data/3306/mysqld.pid		#<==进程号文件

MySQL 3307实例

# cat /data/3307/my.cnf 
[client]								#<==客户端模块
port		=3307						#<==客户端端口
socket		=/data/3307/mysql.sock

[mysqld]								#<==服务端模块
user		=mysql						#<==用户
port		=3307						#<==端口
socket		=/data/3307/mysql.sock		#<==socket路径
basedir		=/application/mysql			#<==安装路径
datadir		=/data/3307/data			#<==数据文件
log-bin		=/data/3307/mysql-bin		#<==二进制日志
server-id	=7

[mysqld_safe]							#<==启动服务模块
log-error	=/data/3307/www_3307.err	#<==错误日志
pid-file	=/data/3307/mysqld.pid		#<==进程号文件

创建MySQL多实例的启动文件

# touch /data/3306/mysql
# touch /data/3307/mysql

MySQL 3306实例启动文件

# cat /data/3306/mysql
#! /bin/bash
port=3306
mysql_user="root"
CmdPath="/application/mysql/bin"
mysql_mycnf="/data/${port}/my.cnf"
mysql_sock="/data/${port}/mysql.sock"
mysqld_pid_file_path="/data/${port}/mysqld.pid"
start(){
	if [ ! -e "$mysql_sock" ];then
		printf "Starting MySQL...\n"
		/bin/sh ${CmdPath}/mysqld_safe --defaults-file=${mysql_mycnf} --pid-file=${mysqld_pid_file_path} 2>&1 > /dev/null &
		sleep 3
	else
		printf "MySQL is running...\n"
		exit 1
	fi
}
stop(){
	if [ ! -e "$mysql_sock" ];then
		printf "MySQL is stopped...\n"
		exit 1
	else
		printf "Stopping MySQL...\n"
		mysqld_pid=`cat ${mysqld_pid_file_path}` #mysqld_pid=`cat "$mysqld_pid_file_path"`
		if ( kill -0 $mysqld_pid 2> /dev/null )
			then
				kill ${mysqld_pid}
				sleep 2
		fi
	fi
}
restart(){
	printf "Restarting MySQL...\n"
	stop
	sleep 2
	start
}
case "$1" in
	start)
		start
	;;
	stop)
		stop
	;;
	restart)
		restart
	;;
	*)
		printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac

MySQL 3307实例启动文件

# cat /data/3307/mysql
#! /bin/bash
port=3307
mysql_user="root"
CmdPath="/application/mysql/bin"
mysql_mycnf="/data/${port}/my.cnf"
mysql_sock="/data/${port}/mysql.sock"
mysqld_pid_file_path="/data/${port}/mysqld.pid"
start(){
	if [ ! -e "$mysql_sock" ];then
		printf "Starting MySQL...\n"
		/bin/sh ${CmdPath}/mysqld_safe --defaults-file=${mysql_mycnf} --pid-file=${mysqld_pid_file_path} 2>&1 > /dev/null &
		sleep 3
	else
		printf "MySQL is running...\n"
		exit 1
	fi
}
stop(){
	if [ ! -e "$mysql_sock" ];then
		printf "MySQL is stopped...\n"
		exit 1
	else
		printf "Stopping MySQL...\n"
		mysqld_pid=`cat ${mysqld_pid_file_path}`
		if ( kill -0 $mysqld_pid 2> /dev/null )
			then
				kill ${mysqld_pid}
				sleep 2
		fi
	fi
}
restart(){
	printf "Restarting MySQL...\n"
	stop
	sleep 2
	start
}
case "$1" in
	start)
		start
	;;
	stop)
		stop
	;;
	restart)
		restart
	;;
	*)
		printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac

需要特别说明一下的是,在多实例启动文件中,启动MySQL不同实例服务所执行的命令实质上是有区别的,例如,
启动3306实例的命令如下:
mysqld_safe --defaults-file=/data/3306/my.cnf > /dev/null 2>&1 &
启动3307实例的命令如下:
mysqld_safe --defaults-file=/data/3307/my.cnf > /dev/null 2>&1 &

mysqladmin命令关闭方法,这个命令的缺点是必须要有数据库的root用户密码才能运行。
停止3306实例的命令如下:
mysqladmin -u root -p密码 -S /data/3306/mysql.sock shutdown
停止3307实例的命令如下:
mysqladmin -u root -p密码 -S /data/3307/mysql.sock shutdown

配置MySQL多实例的文件权限

# touch /data/3306/www_3306.err
# touch /data/3307/www_3307.err
# chown -R mysql:mysql /data
# chmod +x /data/{3306,3307}/mysql

初始化MySQL多实例的数据库

初始化数据库的实质就是创建基础的数据库系统的库文件,例如,生成MySQL库表等。
初始化3306实例数据库:

# cd /application/mysql/scripts
# ./mysql_install_db --defaults-file=/data/3306/my.cnf --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
WARNING: The host 'www' could not be looked up with /application/mysql/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !

Installing MySQL system tables...2019-07-21 16:47:16 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-21 16:47:16 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-07-21 16:47:16 0 [Note] /application/mysql/bin/mysqld (mysqld 5.6.44-log) starting as process 1729 ...
2019-07-21 16:47:16 1729 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-07-21 16:47:16 1729 [Note] InnoDB: The InnoDB memory heap is disabled
2019-07-21 16:47:16 1729 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-07-21 16:47:16 1729 [Note] InnoDB: Memory barrier is not used
2019-07-21 16:47:16 1729 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-07-21 16:47:16 1729 [Note] InnoDB: Using Linux native AIO
2019-07-21 16:47:16 1729 [Note] InnoDB: Using CPU crc32 instructions
2019-07-21 16:47:16 1729 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-07-21 16:47:16 1729 [Note] InnoDB: Completed initialization of buffer pool
2019-07-21 16:47:16 1729 [Note] InnoDB: Highest supported file format is Barracuda.
2019-07-21 16:47:16 1729 [Note] InnoDB: 128 rollback segment(s) are active.
2019-07-21 16:47:16 1729 [Note] InnoDB: Waiting for purge to start
2019-07-21 16:47:16 1729 [Note] InnoDB: 5.6.44 started; log sequence number 1600627
2019-07-21 16:47:17 1729 [Note] Binlog end
2019-07-21 16:47:17 1729 [Note] InnoDB: FTS optimize thread exiting.
2019-07-21 16:47:17 1729 [Note] InnoDB: Starting shutdown...
2019-07-21 16:47:18 1729 [Note] InnoDB: Shutdown completed; log sequence number 1626007
OK

Filling help tables...2019-07-21 16:47:18 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-21 16:47:18 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-07-21 16:47:18 0 [Note] /application/mysql/bin/mysqld (mysqld 5.6.44-log) starting as process 1753 ...
2019-07-21 16:47:18 1753 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-07-21 16:47:18 1753 [Note] InnoDB: The InnoDB memory heap is disabled
2019-07-21 16:47:18 1753 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-07-21 16:47:18 1753 [Note] InnoDB: Memory barrier is not used
2019-07-21 16:47:18 1753 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-07-21 16:47:18 1753 [Note] InnoDB: Using Linux native AIO
2019-07-21 16:47:18 1753 [Note] InnoDB: Using CPU crc32 instructions
2019-07-21 16:47:18 1753 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-07-21 16:47:18 1753 [Note] InnoDB: Completed initialization of buffer pool
2019-07-21 16:47:18 1753 [Note] InnoDB: Highest supported file format is Barracuda.
2019-07-21 16:47:18 1753 [Note] InnoDB: 128 rollback segment(s) are active.
2019-07-21 16:47:18 1753 [Note] InnoDB: Waiting for purge to start
2019-07-21 16:47:18 1753 [Note] InnoDB: 5.6.44 started; log sequence number 1626007
2019-07-21 16:47:19 1753 [Note] Binlog end
2019-07-21 16:47:19 1753 [Note] InnoDB: FTS optimize thread exiting.
2019-07-21 16:47:19 1753 [Note] InnoDB: Starting shutdown...
2019-07-21 16:47:21 1753 [Note] InnoDB: Shutdown completed; log sequence number 1626017
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:

  /application/mysql/bin/mysqladmin -u root password 'new-password'
  /application/mysql/bin/mysqladmin -u root -h www password 'new-password'

Alternatively you can run:

  /application/mysql/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 . ; /application/mysql/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

WARNING: Found existing config file /application/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /application/mysql/my-new.cnf,
please compare it with your file and take the changes you need.

如上,出现两次OK,则成功。

启动MySQL多实例数据库

启动MySQL多实例数据库

# /data/3306/mysql start
# /data/3307/mysql start

同理:关闭MySQL多实例数据库

# /data/3306/mysql stop
# /data/3307/mysql stop

同理:重启MySQL多实例数据库

# /data/3306/mysql restart
# /data/3307/mysql restart

重置root用户密码

MySQL 5.6管理员的账号root密码默认为空,极不安全,可以通过mysqladmin命令为mysql不同实例的数据库设置独立的密码。比如将两个实例的root用户的密码都设置为root。
/application/mysql/bin/目录下的mysqladmin命令。

# mysqladmin -uroot password 'root' -S /data/3306/mysql.sock
# mysqladmin -uroot password 'root' -S /data/3307/mysql.sock

终端登录不同的实例

登录不同的实例需要指定不同实例的sock路径及mysql.sock文件,这个mysql.sock是在my.cnf配置文件里指定的。
登录3306实例

# mysql -uroot -p -S /data/3306/mysql.sock 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.44-log Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

登录3307实例

# mysql -uroot -p -S /data/3307/mysql.sock 
Enter password:

开机启动MySQL多实例数据库

  在 /etc/rc.loadl 文件中加入以下内容:

#mysql multi instances
/data/3306/mysql start
/data/3307/mysql start

远程登录

mysql> use mysql;  
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
mysql> flush privileges; 

//授权语句说明
grant all on xxxx.* to 'root'@'%' identified by 'password' with grant option;
xxxx代表创建的数据库;
%为主机名/主机ip地址
password为用户密码,在此为root的密码

关闭防火墙

查看防火墙状态
firewall-cmd --state
(关闭后显示not running,开启后显示running)

# firewall-cmd --state 

或者systemctl status firewalld.service
(关闭后显示Active: inactive (dead),开启后显示Active: active (running))

# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-07-22 16:38:26 CST; 17s ago
 Main PID: 9242 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─9242 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Jul 22 16:38:25 sy-pc systemd[1]: Starting firewalld - dynamic firewall daemon...
Jul 22 16:38:26 sy-pc systemd[1]: Started firewalld - dynamic firewall daemon.

添加防火墙

# firewall-cmd --zone=public --add-port=3306/tcp --permanent
# firewall-cmd --reload

关闭防火墙

临时关闭防火墙

# systemctl stop firewalld.service

禁止开启启动

# systemctl disable firewalld.service

开启防火墙

# systemctl start firewalld.service

关闭防火墙的步骤为:

# systemctl stop firewalld.service
# systemctl disable firewalld.service

参考文献

[1] 老男孩. 跟老男孩学Linux运维:MySQL入门与提高实践[M]. 机械工业出版社,2019.
[2] CentOS 7下源码安装MySQL 5.6[DB|OL].https://www.linuxidc.com/Linux/2015-06/119354.htm
[3] 设置Mysql5.6允许外网访问详细流程[DB|OL]. https://blog.csdn.net/cxin917/article/details/76686227
[4] mysql开启远程访问权限[DB|OL].https://www.cnblogs.com/hfdp/p/6088288.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值