共计 2390 个字符,预计需要花费 6 分钟才能阅读完成。
前提准备
做测试还是采用二进制方式安装,简单方便快速,在原环境安装好的基础上。
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:
[root@test ~]# 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 登录示例:
[root@test ~]# 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
或采用 kill 方式,或编写启动脚本。
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-04/130733.htm