Home > php教程 > PHP开发 > Multi-instance configuration of mysql5.7.11

Multi-instance configuration of mysql5.7.11

高洛峰
Release: 2016-11-23 09:49:00
Original
1086 people have browsed it

Multi-instance configuration of mysql5.7.11

Mysql has been cleared for a long time and finally reached the second stage. It’s time to do something interesting. I searched on Baidu and found that many of the multi-instances are 5.5, and the 5.7 instructions are not detailed and clear, so I made a simpler tutorial. PS: This is my first time using Markdown; to save time, I installed the rpm package; my level is limited, please correct me; it is not compatible with Mysql5.5.

What you will see are:

Preparation for configuring Mysql multiple instances

Start multiple Mysql instances

Connect Mysql

Some simple settings (optional)

Close Mysql

Add another Mysql instance

1. Preparation for configuring multiple Mysql instances

1.1  创建文件目录

    打算运行两个实例,一个占用3306端口,一个占用3307端口,下面简称3306,3307实例

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

    由于是root创建的还要把权限更改下,这步先放一放留到2.1。

1.2  准备配置文件

    vim编辑两个my.cnf配置文件,编辑完后可以按ZZ或者wq!直接保存退出:        
    简单来说就是1.端口不一样 2.目录路径不同

    实例1的配置文件:

    datadir=/mysql_multi/3306/data
    socket=/mysql_multi/3306/mysql.sock
    log-error=/mysql_multi/3306/mysqld.log
    pid-file=/mysql_multi/3306/mysqld.pid
    server-id=1
    port=3306


    实例2的配置文件:

    datadir=/mysql_multi/3307/data
    socket=/mysql_multi/3307/mysql.sock
    log-error=/mysql_multi/3307/mysqld.log
    pid-file=/mysql_multi/3307/mysqld.pid
    server-id=2
    port=3307

    分别copy到/mysql_multi/3306和/mysql_multi/3307下
Copy after login

2. Start multiple Mysql instances

 2.1  初始化两个Mysql数据库

    先改下目录的权限:
    chown  -R  mysql:mysql   /mysql_multi

    现在是Mysql5.7,之前的5.5都没有这一步。
    对于3306,执行:
    mysqld --defaults-file=/mysql_multi/3306/my.cnf --initialize-insecure --user=mysql

    解释:
    --defaults-file=/mysql_multi/3306/my.cnf  :指定启动的配置文件
    --initialize-insecure :初始化数据库,加上-insecure不生成随机密码
    (直接登陆,不加上-insecure会在mysqld.log生成密码,到时候要自己找  temporary password)
    --user=mysql : 指定用户,这个没什么好说

    3307的也一样:
    mysqld --defaults-file=/mysql_multi/3307/my.cnf --initialize-insecure --user=mysql

    要注意查看data目录下面有没有相关的数据库文件,如果有问题,要看下你的mysqld.log

    2.2  启动实例
   终于到启动实例的关键时刻

    输入:
    启动3306实例:mysqld --defaults-file=/mysql_multi/3306/my.cnf --user=mysql &
    启动3307实例:mysqld --defaults-file=/mysql_multi/3307/my.cnf --user=mysql &

    注意:最后面要加入 &让它运行在后台,不然打完按回车就"卡住"了

    和刚刚差不多就是少了--initialize-insecure初始化数据库这一步,运行成不成功可以看下mysql.log或者
    输入netstat -ntlp 查看下占用端口的进程(成功就可以看到两个mysqld进程,分别占用3306,3307端口)
Copy after login

3. Connect to Mysql

 连接

    连接3306:mysql -uroot -p -S /mysql_multi/3306/mysql.sock
    提示输入密码,直接回车进入。

    连接3307:mysql -uroot -p -S /mysql_multi/3307/mysql.sock
    和上面是一样的

      可以输入 system mysql -S /mysql_multi/3307/mysql.sock切换实例
Copy after login

4. Some simple settings (optional)

 从管理角度来讲,应该要加个system的管理员用作远程管理    
 grant all privileges on *.* to system@'%' identified by '12345678' with grant option;
Copy after login

5. Shut down Mysql

    注意:一定要用mysqladmin关闭
    mysqladmin -S /mysql_multi/3306/mysql.sock shutdown
    mysqladmin -S /mysql_multi/3307/mysql.sock shutdown
Copy after login

6 .Add another Mysql instance

1.  创建相关目录
    mkdir -p  /mysql_multi/3308/data
    2.更改所属用户和所属组
    chown -R mysql:mysql 3308
    3.复制修改配置文件(不细说了)   
    4.初始化: mysqld --defaults-file=/mysql_multi/3308/my.cnf --initialize-insecure --user=mysql
    5.启动:mysqld --defaults-file=/mysql_multi/3308/my.cnf  --user=mysql &
Copy after login

complete~ Finally, a few words: mysqld_safe cannot be found after a certain version of mysql5.7 (Baidu says it is 5.7.9).

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template