一台服务器配置多个mysql实例
在公司资源紧张的情况下,需要在一台服务器上部署多个数据库实例,现在就来实战一下该情况。
需要启动两个不同的端口,分别是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实例的更多相关文章
- CentOS6.5下源码安装多个MySQL实例及复制搭建
多实例安装本节是在CentOS6.5下源码安装MySQL5.6.35的基础上,在同一台机器增加一个MySQL实例.参考Centos中安装多个mysql数据的配置实例,安装目录为/usr/local/m ...
- 同一台windows下配置安装多个mysql实例,实现主从同步
一.安装多个mysql 参见: https://blog.csdn.net/wrh_csdn/article/details/80198795 https://www.cnblogs.com/qjoa ...
- 在一台Linux服务器上安装多个MySQL实例(一)--使用mysqld_multi方式
(一)MySQL多实例概述 实例是进程与内存的一个概述,所谓MySQL多实例,就是在服务器上启动多个相同的MySQL进程,运行在不同的端口(如3306,3307,3308),通过不同的端口对外提供服务 ...
- 存储总量达20T的MySQL实例,如何完成迁移?
版权声明:本文由王亮原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/122 来源:腾云阁 https://www.qclou ...
- 在docker上安装运行mysql实例
ps:实验环境是:CentOS Linux release 7.3 64位1.获取mysql镜像从docker hub的仓库中拉取mysql镜像docker pull mysql查看镜像docker ...
- Windows上安装多个MySQL实例(转)
在学习和开发过程中有时候会用到多个MySQL数据库,比如Master-Slave集群.分库分表,开发阶段在一台机器上安装多个MySQL实例就显得方便不少. 在 MySQL教程-基础篇-1.1-Wind ...
- 全球共有多少MySQL实例在运行?这里有一份数据
摘要 Shadowserver Foundation在5月31日发布了一份全网的MySQL扫描报告,共发现了暴露在公网的360万个MySQL实例.因为这份报告基数够大,而且信息也非常完整,从数据库专业 ...
- 如何安全地关闭MySQL实例
如何安全地关闭MySQL实例 转载自:http://imysql.com/2014/08/13/mysql-faq-howto-shutdown-mysqld-fulgraceful.shtml 本文 ...
- Cent OS服务器配置(JDK+Tomcat+MySQL)
本文摘自:Cent OS服务器配置(JDK+Tomcat+MySQL) 学习tar解压 解压 tar 文件 tar -zxvf apache-tomcat-6.0.35.tar.gz tomcat ...
随机推荐
- 【转载】SpringBoot yml 配置
1. 在 spring boot 中,有两种配置文件,一种是application.properties,另一种是application.yml,两种都可以配置spring boot 项目中的一些变量 ...
- SQL Server系统函数:日期函数
原文:SQL Server系统函数:日期函数 1.返回当前日期和时间 select GETDATE() '当前日期-精确到33毫秒' select GETUTCDATE() 'UTC日期和时间-精确到 ...
- 学HTML第二晚 登录框的制作
进天来弄个登录框 首先,登录框要有登录的账号.密码.和确定.取消的,密码也是要隐藏的. 然后,我们就做: 这是理想中的样子,有了想法,就开始写了 <!dotcype html> <h ...
- Python 生成动态变量 调用动态变量
动态生成变量: variable = locals() for i in range(10): variable['A'+str(i)] = 123 print(A8) 调用动态变量: v = loc ...
- class类 - extends
继承是面向对象中一个比较核心的概念.ES6 class的继承与java的继承大同小异,如果学过java的小伙伴应该很容易理解,都是通过extends关键字继承.相较于ES5当中通过原型链继承要清晰和方 ...
- Ubuntu下双显示器设定
自8.10后的版本,系统自带了xrandr工具,可以很好的实现双显示器.配置与使用如下: 介绍 X Windows 中有一个显示分辨率的概念,在默认情况下,这个显示分辨率为 max*max ,m ...
- 【OGG 故障处理】OGG-01031
故障原因 -------------------- 网络异常,导致DP进程异常中断 故障现象 -------------------- 源端DP 进程全部挂起,且启动失败 GGSCI 34> ...
- coding++ :MySQL函数——FIND_IN_SET()
语法:FIND_IN_SET(str,strlist) 定义: 1). 假如字符串 str 在由N子链组成的字符串列表 strlist 中,则返回值的范围在1到N之间. 2). 一个字符串列表就是一个 ...
- flash多进程写操作
1 应用场景介绍 硬件条件:使用stm32 MCU 软件条件:协议栈应用 协议栈简单介绍如下: 类似于OSI七层模型,所涉及的协议栈包括应用层,网络层,链路层,物理层,如下图: 在 ...
- jade-if-else-unless-case
if else - var lession = ['node','jade'] if lession if lession.length > 2 p 1 #{lession.join(', ') ...