在公司资源紧张的情况下,需要在一台服务器上部署多个数据库实例,现在就来实战一下该情况。

需要启动两个不同的端口,分别是3306和3307

[root@node1 ~]# mkdir /u01/mysql/{3306,3307} -p

[root@node1 ~]# tree /u01/
/u01/
└── mysql
    ├── 3306
    └── 3307

[root@node1 3306]# pwd
/u01/mysql/3306
[root@node1 3306]# vim my.cnf

[root@node1 3306]# grep -v '^#' my.cnf

[mysqld]
datadir=/u01/mysql/3306/data
basedir=/u01/mysql/3306
socket=/u01/mysql/3306/mysql.sock
port=3306
user=root
log_error=/u01/mysql/3306/mysqld.log
symbolic-links=0

初始化数据库:

[root@node1 3306]# mysqld --defaults-file=/u01/mysql/3306/my.cnf --initialize

启动数据库:

[root@node1 3306]# mysqld_safe --defaults-file=/u01/mysql/3306/my.cnf &

数据库的初始密码存在mysqld.log中

[root@node1 3306]# more mysqld.log |grep password
2019-10-21T02:45:19.489156Z 1 [Note] A temporary password is generated for root@localhost: Olp6<bu#op3J

[root@node1 3306]# mysql -uroot -p -S mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> alter user 'root'@'localhost' identified by 'password'

[root@node1 3306]# netstat -tlunp|grep mysqld

tcp6 0 0 :::3306 :::* LISTEN 4401/mysqld

[root@node1 3306]# ps -ef|grep mysqld
root 4245 1 0 10:46 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/u01/mysql/3306/my.cnf
root 4401 4245 0 10:46 ? 00:00:01 /usr/local/src/mysql-5.7.27-linux-glibc2.12-x86_64/bin/mysqld --defaults-file=/u01/mysql/3306/my.cnf --basedir=/u01/mysql/3306 --datadir=/u01/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=root --log-error=/u01/mysql/3306/mysqld.log --pid-file=node1.pid --socket=/u01/mysql/3306/mysql.sock --port=3306

这样3306端口的数据库就可以正常使用了。

3307端口的也是一样的,修改一下配置文件,

[root@node1 3307]# pwd
/u01/mysql/3307
[root@node1 3307]# vim my.cnf

root@node1 3307]# grep -v '^#' my.cnf

[mysqld]
datadir=/u01/mysql/3307/data
basedir=/u01/mysql/3307
socket=/u01/mysql/3307/mysql.sock
port=3307
user=root
log_error=/u01/mysql/3307/mysqld.log
symbolic-links=0

!includedir /etc/my.cnf.d

初始化:

[root@node1 3307]# mysqld --defaults-file=/u01/mysql/3307/my.cnf --initialize

启动数据库:

[root@node1 3307]# mysqld_safe --defaults-file=/u01/mysql/3307/my.cnf &

然后查看初始化密码,登陆进数据库,重置密码。

[root@node1 3307]# netstat -tlunp|grep mysqld
tcp6 0 0 :::3307 :::* LISTEN 5426/mysqld
tcp6 0 0 :::3306 :::* LISTEN 4401/mysqld
[root@node1 3307]# ps -ef|grep mysqld
root 4245 1 0 10:46 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/u01/mysql/3306/my.cnf
root 4401 4245 0 10:46 ? 00:00:02 /usr/local/src/mysql-5.7.27-linux-glibc2.12-x86_64/bin/mysqld --defaults-file=/u01/mysql/3306/my.cnf --basedir=/u01/mysql/3306 --datadir=/u01/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=root --log-error=/u01/mysql/3306/mysqld.log --pid-file=node1.pid --socket=/u01/mysql/3306/mysql.sock --port=3306
root 5268 4147 0 10:58 pts/3 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/u01/mysql/3307/my.cnf
root 5426 5268 0 10:58 pts/3 00:00:01 /usr/local/src/mysql-5.7.27-linux-glibc2.12-x86_64/bin/mysqld --defaults-file=/u01/mysql/3307/my.cnf --basedir=/u01/mysql/3307 --datadir=/u01/mysql/3307/data --plugin-dir=/usr/local/mysql/lib/plugin --user=root --log-error=/u01/mysql/3307/mysqld.log --pid-file=node1.pid --socket=/u01/mysql/3307/mysql.sock --port=3307
root 6155 4147 0 11:41 pts/3 00:00:00 grep --color=auto mysqld

停止数据库:

[root@node1 3307]# mysqladmin -uroot -pWpw303@123 -S /u01/mysql/3307/mysql.sock shutdown  
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
2019-10-21T03:42:10.468422Z mysqld_safe mysqld from pid file /u01/mysql/3307/data/node1.pid ended
[1]+ Done mysqld_safe --defaults-file=/u01/mysql/3307/my.cnf (wd: /u01/mysql/3306)
(wd now: /u01/mysql/3307)
[root@node1 3307]# netstat -tlunp|grep mysqld   只有一个实例了。
tcp6 0 0 :::3306 :::* LISTEN 4401/mysqld

[root@node1 3307]# ps -ef|grep mysqld
root 4245 1 0 10:46 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/u01/mysql/3306/my.cnf
root 4401 4245 0 10:46 ? 00:00:02 /usr/local/src/mysql-5.7.27-linux-glibc2.12-x86_64/bin/mysqld --defaults-file=/u01/mysql/3306/my.cnf --basedir=/u01/mysql/3306 --datadir=/u01/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=root --log-error=/u01/mysql/3306/mysqld.log --pid-file=node1.pid --socket=/u01/mysql/3306/mysql.sock --port=3306
root 6209 4147 0 11:43 pts/3 00:00:00 grep --color=auto mysqld

一台服务器配置多个mysql实例的更多相关文章

  1. CentOS6.5下源码安装多个MySQL实例及复制搭建

    多实例安装本节是在CentOS6.5下源码安装MySQL5.6.35的基础上,在同一台机器增加一个MySQL实例.参考Centos中安装多个mysql数据的配置实例,安装目录为/usr/local/m ...

  2. 同一台windows下配置安装多个mysql实例,实现主从同步

    一.安装多个mysql 参见: https://blog.csdn.net/wrh_csdn/article/details/80198795 https://www.cnblogs.com/qjoa ...

  3. 在一台Linux服务器上安装多个MySQL实例(一)--使用mysqld_multi方式

    (一)MySQL多实例概述 实例是进程与内存的一个概述,所谓MySQL多实例,就是在服务器上启动多个相同的MySQL进程,运行在不同的端口(如3306,3307,3308),通过不同的端口对外提供服务 ...

  4. 存储总量达20T的MySQL实例,如何完成迁移?

    版权声明:本文由王亮原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/122 来源:腾云阁 https://www.qclou ...

  5. 在docker上安装运行mysql实例

    ps:实验环境是:CentOS Linux release 7.3  64位1.获取mysql镜像从docker hub的仓库中拉取mysql镜像docker pull mysql查看镜像docker ...

  6. Windows上安装多个MySQL实例(转)

    在学习和开发过程中有时候会用到多个MySQL数据库,比如Master-Slave集群.分库分表,开发阶段在一台机器上安装多个MySQL实例就显得方便不少. 在 MySQL教程-基础篇-1.1-Wind ...

  7. 全球共有多少MySQL实例在运行?这里有一份数据

    摘要 Shadowserver Foundation在5月31日发布了一份全网的MySQL扫描报告,共发现了暴露在公网的360万个MySQL实例.因为这份报告基数够大,而且信息也非常完整,从数据库专业 ...

  8. 如何安全地关闭MySQL实例

    如何安全地关闭MySQL实例 转载自:http://imysql.com/2014/08/13/mysql-faq-howto-shutdown-mysqld-fulgraceful.shtml 本文 ...

  9. Cent OS服务器配置(JDK+Tomcat+MySQL)

    本文摘自:Cent OS服务器配置(JDK+Tomcat+MySQL) 学习tar解压 解压 tar 文件 tar -zxvf apache-tomcat-6.0.35.tar.gz tomcat   ...

随机推荐

  1. Asp.Net Core 2.0 之旅---@Html.Action

    原文:Asp.Net Core 2.0 之旅---@Html.Action 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https: ...

  2. Django rest-framework框架-组件之渲染器

    渲染器: from rest_framework.renderers import BrowsableAPIRenderer,AdminRenderer,HTMLFormRenderer,JSONRe ...

  3. JDK1.8新特性(一) ----Lambda表达式、Stream API、函数式接口、方法引用

    jdk1.8新特性知识点: Lambda表达式 Stream API 函数式接口 方法引用和构造器调用 接口中的默认方法和静态方法 新时间日期API default   Lambda表达式     L ...

  4. VBA if...elseif...else语句

    一个If语句,后面可以跟一个或多个由布尔表达式组成的elseif语句,然后是一个默认的else语句,当所有条件变为false时执行else语句块. 语法 以下是VBScript中If...Elseif ...

  5. 解决包含在label标签下的checkbox在ie8及以下版本点击事件无效果兼容的问题

    问题描述:     在IE8及以下版本时,点击label标签无法自动触发checkbox的click事件,导致无法产生希望的效果. 原HTML代码: <div class="col-s ...

  6. ES6箭头函数及this指向

    箭头函数(=>):函数简写 无参数:() => {} 单个参数:x => {} 多个参数:(x, y) => {} 解构参数:({x, y}) => {} 嵌套使用:部署 ...

  7. ajax格式,转入后台

    setInterval(function(),时间)定时重复发送请求

  8. Input system (输入子系统)

    Input system (输入子系统) 以前写一些输入设备(键盘,鼠标等)的驱动都是字符设备,混杂设备处理的,linux开源社区的大神门看到了这大量的输入设备如此分散不堪,就想有木有一种机制,可以对 ...

  9. 【leetcode】637. Average of Levels in Binary Tree

    原题 Given a non-empty binary tree, return the average value of the nodes on each level in the form of ...

  10. 清除keil编译中间文件的脚本

    清除keil编译生成的中间文件,减小项目体积. keykill.bat del *.bak /s del *.ddk /s del *.edk /s del *.lst /s del *.lnp /s ...