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

需要启动两个不同的端口,分别是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. (七)springmvc之ModelAttribute注解

    一.没有使用@ModelAttribute的Controller方法. @RequestMapping("/save") public String save(User user) ...

  2. JavaScript--常用对象的属性及方法(1)

    1.Number对象(基本数据类型) Number对象的方法大多是一些强制转换方法,如果转换失败返回NaN,以下举例中用number来代替具体数字: *console.log在控制台输出(键盘F12可 ...

  3. CVE-2019-0214: Apache Archiva arbitrary file write and delete on the server

    CVE-2019-0214: Apache Archiva arbitrary file write and delete on the server Severity: Medium Vendor: ...

  4. import的本质

    import本质? 1定义: 模块:用来从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能,本质上是一个.py结尾的python文件)(文件:text.py 对应的模块名:text) 包 ...

  5. webpack中shimming的概念

    在webpack打包过程中会去做一些代码上的兼容,或者打包过程的兼容,比如之前使用过的babel-polyfill这个工具,他解决了es6代码在低版本浏览器的兼容.这就是webpack中的垫片.他解决 ...

  6. 【转】关于 Goroutine Channel Select 的用法和理解

    原文:https://blog.csdn.net/jfkidear/article/details/88661693 ----------------------------------------- ...

  7. 部署logstash节点

    .部署Logstash节点 1.查看系统环境: [root@Logstash ~]# hostname Logstash [root@Logstash ~]# cat /etc/redhat-rele ...

  8. Java并发包--线程池原理

    转载请注明出处:http://www.cnblogs.com/skywang12345/p/3509954.html 线程池示例 在分析线程池之前,先看一个简单的线程池示例. 1 import jav ...

  9. JavaScript 基础知识 - BOM篇

    前言 本篇文章是JavaScript基础知识的BOM篇,如果前面的<JavaScript基础知识-DOM篇>看完了,现在就可以学习BOM了. 注意: 所有的案例都在这里链接: 提取密码密码 ...

  10. c#截图功能

    简化版: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...