您好,登录后才能下订单哦!
下文主要给大家带来MySQL多实例创建及配置的步骤,希望这些内容能够带给大家实际用处,这也是我编辑MySQL多实例创建及配置的步骤这篇文章的主要目的。好了,废话不多说,大家直接看下文吧。
3306 3307 3308
多个mysqld进程(mysqld_safe)
多个配置文件(port、server_id datadir log-error log-bin socket)
管理多套数据(多个数据目录,分别初始化数据)
创建mkdir -p /data/{3306,3307,3308}
多实例:
3306 3307 3308
多个mysqld 进程(mysqld_safe)
多个配置文件(port server_id datadir log-error log-bin socket)
管理多套数据(多个数据目录,分别初始化数据)
mkdir -p {3306,3307,3308}
vim /data/3306/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3306/data
server-id=3306
port=3306
log-bin=/data/3306/mysql-bin
socket=/data/3306/mysql.sock
log-error=/data/3306/mysql.log
vim /data/3307/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3307/data
server-id=3307
port=3307
log-bin=/data/3307/mysql-bin
socket=/data/3307/mysql.sock
log-error=/data/3307/mysql.log
vim /data/3308/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3308/data
server-id=3308
port=3308
log-bin=/data/3308/mysql-bin
socket=/data/3308/mysql.sock
log-error=/data/3308/mysql.log
cd /application/mysql/scripts
./mysql_install_db --defaults-file=/data/3306/my.cnf --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
./mysql_install_db --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307/data --user=mysql
./mysql_install_db --defaults-file=/data/3308/my.cnf --basedir=/application/mysql --datadir=/data/3308/data --user=mysql
/application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf &
/application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf &
/application/mysql/bin/mysqld_safe --defaults-file=/data/3308/my.cnf &
[root@db02 /data/3307/data]$netstat -lnp|grep 330
tcp 0 0 :::3306 :::* LISTEN 3877/mysqld
tcp 0 0 :::3307 :::* LISTEN 4048/mysqld
tcp 0 0 :::3308 :::* LISTEN 4219/mysqld
unix 2 [ ACC ] STREAM LISTENING 18009 3877/mysqld /data/3306/mysql.sock
unix 2 [ ACC ] STREAM LISTENING 18137 4048/mysqld /data/3307/mysql.sock
unix 2 [ ACC ] STREAM LISTENING 18265 4219/mysqld /data/3308/mysql.sock
说明:登录可以输入下面的命令或者是
[root@db02 ~]$mysql -S /data/3306/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.36-log Source distribution
Copyright (c) 2000, 2017, 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 |
| test |
+--------------------+
4 rows in set (0.18 sec)
说明:以下命令也可操作:
mysql -uroot -p -P3308
mysql -uroot -p -S /tmp/mysql3307.sock
说明:在多实例关闭的时候指定关闭的端口即可。
[root@db02 /]$mysqladmin shutdown -S /data/3306/mysql.sock
[root@db02 /]$ps -ef|grep 330
root 1330 1 0 08:49 ? 00:00:00 /usr/sbin/acpid
root 2520 2088 0 22:25 pts/1 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf
mysql 2815 2520 0 22:25 pts/1 00:00:12 /application/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3307/mysql.log --pid-file=/data/3307/data/db02.pid --socket=/data/3307/mysql.sock --port=3307
root 2879 2088 0 22:25 pts/1 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3308/my.cnf
mysql 3028 2879 0 22:25 pts/1 00:00:10 /application/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf --basedir=/application/mysql --datadir=/data/3308/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3308/mysql.log --pid-file=/data/3308/data/db02.pid --socket=/data/3308/mysql.sock --port=3308
root 3288 3146 0 23:14 pts/2 00:00:00 grep 330
备注:以下命令
关闭MySQL数据库
# mysqld_multi stop 3306
# mysqld_multi stop 3307,3308,3309
# ps -ef | grep mysqld
root 30822 12043 0 23:04 pts/0 00:00:00 grep mysqld
对于以上关于MySQL多实例创建及配置的步骤,大家是不是觉得非常有帮助。如果需要了解更多内容,请继续关注我们的行业资讯,相信你会喜欢上这些内容的。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。