CentOS6.5 上部署 MySQL5.7.17 二进制安装以及多实例配置

1、建用户、下载、解压

groupadd mysql
useradd -r -g mysql mysql
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
tar xvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
ln -sv /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql

2、输出环境变量、帮助

/etc/profile
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
vim /etc/man.config
MANPATH /usr/local/mysql/man

3、创建数据目录、授权、初始化mysql mysql5.7.7及以上做了很多改变,5.7.7以前安装方法和以前差不多,初始化也保留了mysql_install_db,5.7.7以后则去掉了该脚本,使用了-initialize 或者 --initialize-insecure 参数作为初始化。

mysql5.7.14版本初始化时候已经抛弃了defaults-file参数文件,所以在初始化时候指定配置文件会出错,同时必须保证datadir为空。

mkdir /data/mysql
chown mysql.mysql /data/mysql
[root@leo mysql]# mysqld --verbose --help |more 查看更多初始化参数
[root@leo mysql]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2016-12-21T09:37:13.532770Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-12-21T09:37:16.364569Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-21T09:37:16.881727Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-12-21T09:37:17.115686Z 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: 0fbca93f-c761-11e6-9409-000c299a8601.
2016-12-21T09:37:17.220886Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-12-21T09:37:17.284087Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

初始化成功了。这里说明下,初始化参数我使用了--initialize-insecure,这样不会设置初始化root密码,如果是 --initialize的话,会随机生成一个密码:

4、设置加密连接

[root@leo mysql]# /usr/local/mysql/bin/mysql_ssl_rsa_setup
Generating a 2048 bit RSA private key
..........................................................+++
.......+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
...........+++
...........................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
............................................+++
.............................................................+++
writing new private key to 'client-key.pem'
-----

5、复制配置文件和启动脚本

[root@leo mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@leo mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

6、配置如下

[root@leo mysql]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[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
# These are commonly set, remove the # and set as required.
basedir=/usr/local/mysql
datadir=/data/mysql
port=3306
server_id=1
socket=/data/mysql/mysql.sock
symbolic-links=0
character_set_server=utf8
# 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
[client]
socket=/data/mysql/mysql.sock

7、启动、并查看日志

[root@leo ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/leo.err'.
.                             [确定]
[root@leo ~]# /etc/init.d/mysqld restart
Shutting down MySQL..                   [确定]
Starting MySQL..                      [确定]
[root@leo ~]# tail -f /data/mysql/leo.err
2016-12-21T09:42:48.493804Z 0 [Note]  - '::' resolves to '::';
2016-12-21T09:42:48.493834Z 0 [Note] Server socket created on IP: '::'.
2016-12-21T09:42:48.493990Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql/ib_buffer_pool
2016-12-21T09:42:48.496446Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161221 17:42:48
2016-12-21T09:42:48.512719Z 0 [Note] Event Scheduler: Loaded 0 events
2016-12-21T09:42:48.512907Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
2016-12-21T09:42:48.512922Z 0 [Note] Beginning of list of non-natively partitioned tables
2016-12-21T09:42:48.529189Z 0 [Note] End of list of non-natively partitioned tables
2016-12-21T09:42:48.529703Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.7.17' socket: '/data/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)

8、登录测试

[root@leo mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
+--------------------+
4 rows in set (0.01 sec)
mysql>
[root@leo mysql]# ps -ef |grep mysql
root   49305   1 0 17:54 pts/0  00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/leo.pid
mysql   49501 49305 0 17:54 pts/0  00:00: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/leo.err --pid-file=/data/mysql/leo.pid --socket=/data/mysql/mysql.sock --port=3306
root   49598 46306 0 18:14 pts/0  00:00:00 grep mysql

多实例配置部分

1、复制多实例启动脚本

[root@leo ~]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi

2、初始化数据库目录并修改多实例配置文件

mkdir /data/mysql2
mkdir /data/mysql3
chown mysql.mysql /data/mysql2
chown mysql.mysql /data/mysql3
[root@leo ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql2
2016-12-21T16:36:00.886650Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-12-21T16:36:06.481686Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-21T16:36:07.145444Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-12-21T16:36:07.443823Z 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: 92945fc8-c79b-11e6-88a5-000c299a8601.
2016-12-21T16:36:07.453113Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-12-21T16:36:07.456819Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@leo ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3
2016-12-21T16:36:16.094948Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-12-21T16:36:21.224144Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-21T16:36:21.900500Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-12-21T16:36:22.095535Z 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: 9b500f71-c79b-11e6-8af0-000c299a8601.
2016-12-21T16:36:22.105950Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-12-21T16:36:22.112685Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@leo ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld_multi]
mysqld=/usr/local/mysql/bin/mysqld_safe
mysqladmin=/usr/local/mysql/bin/mysqladmin
log=/data/mysql_multi.log
user = root
password = redhat
# 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
# These are commonly set, remove the # and set as required.
[mysqld1]
basedir=/usr/local/mysql
datadir=/data/mysql
port=3306
server_id=1
socket=/data/mysql/mysql.sock
symbolic-links=0
character_set_server=utf8
pid-file=/data/mysql/mysql.pid
[mysqld2]
datadir=/data/mysql2
port=3307
socket=/data/mysql2/mysql.sock
symbolic-links=0
character_set_server=utf8
pid-file=/data/mysql2/mysql2.pid
[mysqld3]
datadir=/data/mysql3
port=3308
socket=/data/mysql3/mysql.sock
symbolic-links=0
character_set_server=utf8
pid-file=/data/mysql3/mysql3.pid
# 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
#[client]
#socket=/data/mysql/mysql.sock

3、启动多实例测试并查看日志

[root@leo ~]# /etc/init.d/mysqld_multi start
[root@leo ~]# /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
[root@leo ~]# netstat -antlp |grep :330*
tcp    0   0 :::3307           :::*            LISTEN   55762/mysqld
tcp    0   0 :::3308           :::*            LISTEN   55765/mysqld
tcp    0   0 :::3306           :::*            LISTEN   55764/mysqld

4、连接测试

[root@leo ~]# mysql -uroot -h127.0.0.1 -P3308 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
+--------------------+
4 rows in set (0.00 sec)
mysql> grant shutdown on *.* to 'root'@'%' identified by 'redhat'; #授权
Query OK, 0 rows affected, 1 warning (0.08 sec)
mysql>flush provileges;
update mysql.user set authentication_string=password('redhat') where user='root' and Host = 'localhost';#设置mysql登录密码
[root@leo ~]# mysqladmin -uroot -p -S /data/mysql3/mysql.sock shutdown #关闭实例
Enter password:

5、附带脚本多实例管理脚本

stop关闭MySQL实例,注意此处是需要一个具有shutdown权限的用户,且密码并被是加密的,也不可以交互式输入密码,Linux又具有history功能,所以为了数据库的安全,还是不要用mysqld_multi stop的方式关闭数据库了吧

[root@leo ~]# cat /etc/init.d/mysqld_multi
#!/bin/sh
#
# A simple startup script for mysqld_multi by Tim Smith and Jani Tolonen.
# This script assumes that my.cnf file exists either in /etc/my.cnf or
# /root/.my.cnf and has groups [mysqld_multi] and [mysqldN]. See the
# mysqld_multi documentation for detailed instructions.
#
# This script can be used as /etc/init.d/mysql.server
#
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.
#
# Version 1.0
#
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
conf=/etc/my.cnf
if test -x $bindir/mysqld_multi
then
 mysqld_multi="$bindir/mysqld_multi";
else
 echo "Can't execute $bindir/mysqld_multi from dir $basedir";
 exit;
fi
case "$1" in
  'start' )
    "$mysqld_multi" --defaults-extra-file=$conf start $2
    ;;
  'stop' )
    "$mysqld_multi" --defaults-extra-file=$conf stop $2 --user=root --password=redhat
    ;;
  'report' )
    "$mysqld_multi" --defaults-extra-file=$conf report $2
    ;;
  'restart' )
    "$mysqld_multi" --defaults-extra-file=$conf stop $2 --user=root --password=redhat
    "$mysqld_multi" --defaults-extra-file=$conf start $2
    ;;
  *)
    echo "Usage: $0 {start|stop|report|restart}" >&2
    ;;
esac

6、多实例测试启停

[root@leo ~]# /etc/init.d/mysqld_multi stop
[root@leo ~]# /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
MySQL server from group: mysqld3 is not running
[root@leo ~]# /etc/init.d/mysqld_multi start
[root@leo ~]# /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
[root@leo ~]# netstat -antlp |grep :330* #查看监听端口
tcp    0   0 :::3307           :::*            LISTEN   74667/mysqld
tcp    0   0 :::3308           :::*            LISTEN   74666/mysqld
tcp    0   0 :::3306           :::*            LISTEN   74665/mysqld
[root@leo ~]# mysql -uroot -predhat -P3307 -h127.0.0.1 #登录3307 测试
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
| t1         |
+--------------------+
5 rows in set (0.13 sec)
mysql>
[root@leo ~]# tail -f /data/mysql3/leo.err  #查看日志
2016-12-21T21:47:56.114139Z 0 [Note] Server hostname (bind-address): '*'; port: 3308
2016-12-21T21:47:56.145404Z 0 [Note] IPv6 is available.
2016-12-21T21:47:56.169487Z 0 [Note]  - '::' resolves to '::';
2016-12-21T21:47:56.171033Z 0 [Note] Server socket created on IP: '::'.
2016-12-21T21:47:57.157171Z 0 [Note] Event Scheduler: Loaded 0 events
2016-12-21T21:47:57.157710Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
2016-12-21T21:47:57.157729Z 0 [Note] Beginning of list of non-natively partitioned tables
2016-12-21T21:47:58.138317Z 0 [Note] End of list of non-natively partitioned tables
2016-12-21T21:47:58.138474Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.7.17' socket: '/data/mysql3/mysql.sock' port: 3308 MySQL Community Server (GPL)

mysqld_multi启动会查找my.cnf文件中的[mysqldN]组,N为mysqld_multi后携带的整数值。 mysqld_multi的固定选项可在配置文件my.cnf中进行配置,在[mysqld_multi]组下配置(如果没有该组,可自行建立)。 mysqld_multi使用方式如下: mysqld_multi [options] {start|stop|reload|report} [GNR[,GNR] ...]

以上所述是小编给大家介绍的CentOS6.5 上部署 MySQL5.7.17 二进制安装以及多实例配置,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

(0)

相关推荐

  • MySQL5.7.17安装及配置图文教程

    博主说:最近在写「史上最简单的 MySQL 教程」系列博文,写着写着,忽然想到或许有些童鞋还没有接触过 MySQL 数据库呢?理论与实践相结合才是王道啊,因此有了这篇关于 MySQL 数据库的安装及配置介绍的博文.说实话,这篇博文并没有什么技术含量,姑且给未接触过 MySQL 数据库的童鞋一些参考吧! 首先,下载 MySQL 数据库的安装包:mysql-5.7.17.msi.链接: https://pan.baidu.com/s/1nuVVEEd 密码: 2fxw 下载完成之后,双击打开此msi

  • Linux系统下使用rpm方式安装最新mysql5.7.17完整步骤

    1.下载以及前面的rpm安装步骤请参照 Linux 使用rpm方式安装最新mysql(5.7.16)步骤以及常见问题解决 2.四个rpm包安装完成后执行mysqld --initialize --user=mysql 如果提示目的文件夹内有文件: 直接将/var/lib/mysql/ 文件夹下的文件删除干净再次执行. 完成后 进入日志文件查找初始化生成的密码vi /var/log/mysqld.log 3.登录修改密码 mysql -u root -p 第一次更改密码前所有的操作都是禁止的,依次

  • mysql5.7.17安装使用图文教程

    MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司.MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性.MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言.MySQL软件采用了双授权政策(本词条"授权政策"),它分为社区版和商业版,由于其体积小.速度快.总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择MySQL作为网站数据库.由于

  • mysql5.7.17 zip 解压安装详细过程

    一.下载地址 https://dev.mysql.com/downloads/mysql/,选择合适版本进行下载. 二.解压文件到指定目录 例如,我的mysql目录为"D:\Program Files\mysql57",在该目录下新建孔目录data. 三.修改配置文件my-default.ini文件 四.初始化mysql ,进入bin目录,在命令行中输入mysqld --initialize-insecure --user=mysql 使用-initialize生成随机密码,由于自己学

  • mysql5.7.17.msi安装图文教程

    mysql-5.7.17.msi安装,跟着截图摩擦,一步一步是爪牙,是魔鬼的步伐 开始: 可以创建其他用户 我自己改了日志名 精彩专题分享:mysql不同版本安装教程 mysql5.7各版本安装教程 mysql5.6各版本安装教程 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们.

  • mysql5.7.17安装配置图文教程

    My SQL的特点: MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件. MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性. MySQL所使用的

  • Linux(Ubuntu)下mysql5.7.17安装配置方法图文教程

    前言 前面安装过mysql5.6,时隔三个月,开发那边反馈需要在MySQL中处理JSON类型的数据,查看文档,JSON是在5.7支持的新特性.于是着手安装Mysql57 Mysql5.6.28的安装:http://www.jb51.net/article/103743.htm 安装 若使用apt-get install mysql-server进行安装,默认安装的不是最新的版本,于是考虑去官网找一个最新的社区版本. 1.获取最新的Mysql版本 在 https://dev.mysql.com/d

  • windows10安装mysql5.7.17教程

    本教程为大家分享了mysql5.7.17安装配置方法,供大家参考,具体内容如下 操作 全允许 精彩专题分享:mysql不同版本安装教程 mysql5.7各版本安装教程 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们.

  • linux下mysql5.7.17最新稳定版本安装教程

    通过源码在linux上安装mysql最新稳定版本:mysql-5.7.17 为了方便安装过程中不受boost依赖的影响,直接从官网下载mysql-boost-5.7.17.tar.gz版本.(官方解释,编译过程中需要boost,但实际没有用到.) 安装目录: 启动脚本:/etc/init.d/mysqld 程序根目录:/usr/local/mysql 数据目录:/data/mysql 安装过程 1.安装依赖 #yum install -y cmake gcc-c++* make ncurses-

  • Window 下安装Mysql5.7.17 及设置编码为utf8的方法

    下载 mysql官方下载 选择Windows (x86, 64-bit), ZIP Archive 安装 1.解压 我这里解压到D盘根目录 2.进行初始化 mysql5.7之后 默认不会有data目录 所以初始化命令有所改变 打开cmd 进入mysql的bin目录,之后的命令必须在bin目录下运行(即使配置了环境变量也必须这样) mysqld--initialize-insecure 这个方法初始化完后,root用户无密码 mysqld--initialize --console.这个方法初始化

随机推荐