mysql 5.6 多实例_MySQL 5.6.x多实例配置

前提准备

做测试还是采用二进制方式安装,简单方便快速,在原环境安装好的基础上。

MySQL-5.6.x二进制版本安装记录   http://www.linuxidc.com/Linux/2016-04/130028.htm

个人不喜欢采用mysqlmulti方式配置多实例,还是采用多实例多进程方式配置。

1, 准备数据库实例datadir目录

# mkdir -p /usr/local/mysql/mysql3307

# chown mysql:mysql /usr/local/mysql/mysql3307

初始化实例目录

# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/mysql3307

2. 准备配置文件

(1) 修改现有配置文件名my.cnf修为3306.cnf,并复制一个配置文件名为3307.cnf

(2) 3306.cnf配置文件修改,端口,sock位置,pid位置,datadir位置等。

[client]

port        = 3306

socket      = /tmp/mysql3306.sock

[mysqld]

port        = 3306

socket      = /tmp/mysql3306.sock

datadir    = /usr/local/mysql/data

(3) 3307.cnf配置文件修改

[client]

port        = 3307

socket      = /tmp/mysql3307.sock

[mysqld]

port        = 3307

socket      = /tmp/mysql3307.sock

datadir    = /usr/local/mysql/mysql3307

3. 启动多实例,启动脚本可以加入到开机自启动文件中。

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/3306.cnf 2>&1 >/dev/null &

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/3307.cnf 2>&1 >/dev/null &

4. 数据库登录

# /usr/local/mysql/bin/mysql -u root -p -P 3306 -S /tmp/mysql3306.sock

# /usr/local/mysql/bin/mysql -u root -p -P 3307 -S /tmp/mysql3307.sock

修改3307实例密码:

# /usr/local/mysql/bin/mysqladmin -u root password 'admin' -S /tmp/mysql3307.sock  #设置管理员密码

3306登录示例1:

[[email protected] ~]# mysql -uroot -p -S /tmp/mysql3306.sock

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 14

Server version: 5.6.24-log Source distribution

Copyright (c) 2000, 2015, 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> \q

Bye

3307登录示例:

[[email protected] ~]# mysql -uroot -p  -S /tmp/mysql3307.sock

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 15

Server version: 5.6.24-log Source distribution

Copyright (c) 2000, 2015, 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 -uroot -p -h127.0.0.1 -P3307

5. 关闭mysql多实例方式

# /usr/local/mysql/bin/mysqladmin -u root -p -P 3306 -S /tmp/mysql3306.sock shutdown

# /usr/local/mysql/bin/mysqladmin -u root -p -P 3307 -S /tmp/mysql3307.sock shutdown

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值