一台服务器配置多个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 ...
随机推荐
- office2016激活码 最新各个版本 激活
office2016专业版激活密钥 Microsoft Office 2016 Pro Plus Retail 零售版序列号密钥: BHXN7-MQB36-MTHQ4-8MHKV-CYT97 Micr ...
- ASP.NET Core 入门(1)(搭建环境CentOS)
一.CentOS 7 安装 下载CentOS http://isoredirect.centos.org/centos/7/isos/x86_64/ 选择其中下载即可. 下载完成后打开vmware准 ...
- OSI的七层网络模型
一.概念七层模型,亦称OSI(Open System Interconnection)参考模型,是参考模型是国际标准化组织(ISO)制定的一个用于计算机或通信系统间互联的标准体系.它是一个七层的.抽象 ...
- Oracle insert /*+ APPEND */原理解析
https://blog.csdn.net/xiaobluesky/article/details/50494101 关于insert /*+ append */我们需要注意以下三点: a.非归档模式 ...
- Delphi 安装apk
procedure ToInstallApk(filename: string); var aFile: Jfile; Intent: JIntent; begin Try aFile := TJfi ...
- vue组件间的传值方式及方法调用汇总
1.传值 a.父组件传子组件 方法一: 父页面: <myReportContent v-if="contentState==1" :paramsProps='paramsPr ...
- word生成目录的pdf
在很多情况下,需要将Word转换为带目录书签的PDF,方便pdf阅读,所以可以使用word自带的pdf转换,在转换时设置相关即可 注意:待转换Word中应该有目录,可以用Word中的标题来自动生成目录 ...
- 解决在Linux操作系统下无法连接MySQL服务端的问题
遇到这种问题的时候我们需要考虑的是防火墙规则,因为防火墙默认是禁止所有端口访问的,所以我们需要添加一个访问端口来连接MySQL. 命令如下: 允许某端口 firewall-cmd --zone= ...
- 【问题】使用XShell连接Debian,没有语法高亮
编辑家目录里面的.bashrc文件,取消红框中的注释. 我使用的是XShell连接Debian,有的人可能改完也没有语法高亮,试着改下XShell的配色方案 参考:https://www.cnblog ...
- 测试某网站的SMS验证码
to=18911121211&sms_type=sms_registration&captcha_num=9JCMw4yN5EjI6ISYoNGdwF2YiwiIw5WNwlmb3xm ...