加载中...

Mysql 5.6配置多实例


一、准备环境

1.1 创建数据目录准备配置文件

[root@db data]# mkdir /data/{3307,3308}
[root@db data]# cat 3307/my.conf
[mysqld]
basedir=/application/mysql/
datadir=/data/3307/data
socket=/data/3307/data/mysql.sock
port=3307
log_err=/data/3307/mysql.err
log-bin=/data/3307/mysql-bin
server_id=7
#复制配置文件到3308
[root@db data]# cp 3307/my.conf 3308/
#给数据目录属主属组
chown -R mysql:mysql /data

二、配置启动

2.1 初始化

#需要到mysql安装目录下的script中执行
[root@db data]# cd /application/mysql/scripts/
[root@db data]# ./mysql_install_db --defaults-file=/data/3307/my.conf --basedir=/application/mysql --datadir=/data/3307/data
[root@db data]# ./mysql_install_db --defaults-file=/data/3308/my.conf --basedir=/application/mysql --datadir=/data/3308/data
#查看目录结果
[root@db data]# tree -L 2 /data
/data
├── 3307
│   ├── data
│   ├── my.conf
│   ├── mysql-bin.000001
│   ├── mysql-bin.000002
│   ├── mysql-bin.000003
│   ├── mysql-bin.index
│   └── mysql.err
└── 3308
    ├── data
    ├── my.conf
    ├── mysql-bin.000001
    ├── mysql-bin.000002
    ├── mysql-bin.000003
    ├── mysql-bin.index
    └── mysql.err

2.2 启动

[root@db data]# mysqld_safe --defaults-file=/data/3307/my.conf &
[root@db data]# mysqld_safe --defaults-file=/data/3308/my.conf &
#查看端口确认是否启动
[root@db data]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1530/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1182/master
tcp        0     52 192.168.0.49:22         106.75.220.2:54310      ESTABLISHED 17531/sshd: root@pt
tcp        0      0 192.168.0.49:22         106.75.220.2:58731      ESTABLISHED 8275/sshd: root@pts
tcp6       0      0 :::22                   :::*                    LISTEN      1530/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1182/master
tcp6       0      0 :::3306                 :::*                    LISTEN      17293/mysqld
tcp6       0      0 :::3307                 :::*                    LISTEN      16924/mysqld
tcp6       0      0 :::3308                 :::*                    LISTEN      17104/mysqld

2.3 修改密码

[root@db data]# mysqladmin -uroot -p -S /data/3307/data/mysql.sock password '3307'
Enter password:
Warning: Using a password on the command line interface can be insecure.
[root@db data]# mysqladmin -uroot -p -S /data/3308/data/mysql.sock password '3308'
Enter password:
Warning: Using a password on the command line interface can be insecure.

2.4 登陆确认

[root@db data]# mysql -uroot -p3307 -S /data/3307/data/mysql.sock -e "show variables like 'server_id';"
Warning: Using a password on the command line interface can be insecure.
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 7     |
+---------------+-------+
[root@db data]# mysql -uroot -p3308 -S /data/3308/data/mysql.sock -e "show variables like 'server_id';"
Warning: Using a password on the command line interface can be insecure.
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 8     |
+---------------+-------+

三、调优

3.1 配置启动脚本

[root@db data]# cat /usr/local/bin/mysql3307
mysql -uroot -p3307 -S /data/3307/data/mysql.sock
[root@db data]# chmod 700 /usr/local/bin/mysql3307
[root@db data]# cat /usr/local/bin/mysql3308
mysql -uroot -p3308 -S /data/3308/data/mysql.sock
[root@db data]# chmod 700 /usr/local/bin/mysql3308
#测试连接
[root@db data]# mysql3307
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 11
Server version: 5.6.40-log Source distribution

Copyright (c) 2000, 2018, 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 variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 7     |
+---------------+-------+
1 row in set (0.00 sec)
[root@db data]# mysql3308
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.6.40-log Source distribution

Copyright (c) 2000, 2018, 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 variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 8     |
+---------------+-------+
1 row in set (0.00 sec)

文章作者: huhuhahei
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 huhuhahei !
评论
  目录