MySQL数据库入门多实例配置
MySQL数据库入门——多实例配置
前面介绍了相关的基础命令操作,所有的操作都是基于单实例的,mysql多实例在实际生产环境也是非常实用的,因为必须要掌握
1、什么是多实例
多实例就是一台服务器上开启多个不同的服务端口(默认3306),运行多个mysql的服务进程,这此服务进程通过不同的socket监听不同的服务端口来提供各在的服务,所有实例之间共同使用一套MYSQL的安装程序,但各自使用不同的配置文件、启动程序、数据文件,在逻辑上是相对独立的。
多实例主要作用是:充分利用现有的服务器硬件资源,为不同的服务提供数据服务,但是如果某个实例并发比较高的,同样是会影响到其它实例的性能
2、安装多实例环境准备
安装前需要先安装mysql,但是只需将安装过程进行到make install即可(编译安装),如果使用免安装程序,只需解压软件包即可,今天的环境是通过免安装包来安装mysql主程序(其它的安装可以参考前面的安装过程自行测试)
系统环境
[root@centos6 ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@centos6 ~]# uname -r
2.6.32-431.el6.x86_64
安装程序
mysql-5.5.52-linux2.6-x86_64.tar.gz
首先将软件下载到本地
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.52-linux2.6-x86_64.tar.gz
创建安装用户
[root@centos6 ~]#groupadd mysql
[root@centos6 ~]#useradd mysql -s /sbin/nologin -g mysql -M
[root@centos6 ~]#tail -1 /etc/passwd
mysql:x:500:500::/home/mysql:/sbin/nologin
创建多实例的数据目录
[root@centos6 tools]# mkdir -p /data/{3306,3307}
[root@centos6 tools]# tree /data/
/data/
+-- 3306
+-- 3307
2 directories, 0 files
3、安装MYSQL多实例
接下来进行安装mysql的多实例操作
解压软件
[root@centos6 tools]# ll mysql-5.5.52-linux2.6-x86_64.tar.gz
-rw-r--r--. 1 root root 185855000 Aug 26 21:38 mysql-5.5.52-linux2.6-x86_64.tar.gz
[root@centos6 tools]# tar zxf mysql-5.5.52-linux2.6-x86_64.tar.gz
拷贝配置文件
[root@centos6 mysql-5.5.52-linux2.6-x86_64]# cp support-files/my-small.cnf /data/3306/my.cnf
[root@centos6 mysql-5.5.52-linux2.6-x86_64]# cp support-files/mysql.server /data/3306/mysql
[root@centos6 mysql-5.5.52-linux2.6-x86_64]# cp support-files/my-small.cnf /data/3307/my.cnf
[root@centos6 mysql-5.5.52-linux2.6-x86_64]# cp support-files/mysql.server /data/3307/mysql
为一规范安装路径,将免安装包拷贝到应用程序目录下
[root@centos6 tools]# mv mysql-5.5.52-linux2.6-x86_64 /application/mysql
[root@centos6 tools]# ll /application/mysql
total 72
drwxr-xr-x. 2 root root 4096 Dec 9 17:15 bin
-rw-r--r--. 1 7161 31415 17987 Aug 26 19:24 COPYING
drwxr-xr-x. 3 root root 4096 Dec 9 17:15 data
drwxr-xr-x. 2 root root 4096 Dec 9 17:15 docs
drwxr-xr-x. 3 root root 4096 Dec 9 17:15 include
-rw-r--r--. 1 7161 31415 301 Aug 26 19:24 INSTALL-BINARY
drwxr-xr-x. 3 root root 4096 Dec 9 17:15 lib
drwxr-xr-x. 4 root root 4096 Dec 9 17:15 man
drwxr-xr-x. 10 root root 4096 Dec 9 17:15 mysql-test
-rw-r--r--. 1 7161 31415 2496 Aug 26 19:24 README
drwxr-xr-x. 2 root root 4096 Dec 9 17:15 scripts
drwxr-xr-x. 27 root root 4096 Dec 9 17:15 share
drwxr-xr-x. 4 root root 4096 Dec 9 17:15 sql-bench
drwxr-xr-x. 2 root root 4096 Dec 9 17:15 support-files
修改配置文件与启动文件
因为是多实例,其中参数需要修改,修改后的配置文件如下
配置文件my.cnf
[client]
port = 3307
socket = /data/3307/mysql.sock
[mysql]
no-auto-rehash
[mysqld] user = mysql
port = 3307
socket = /data/3307/mysql.sock
basedir = /application/mysql
datadir = /data/3307/data
#log_long_format
#log-error = /data/3307/error.log
#log-slow-queries = /data/3307/slow.log
pid-file = /data/3307/mysql.pid
server-id = 3
[mysqld_safe]
log-error=/data/3307/mysql3307.err
pid-file=/data/3307/mysqld.pid
启动程序文件mysql
[root@backup 3307]# cat mysql
#!/bin/sh
init port=3307
mysql_user="root"
mysql_pwd="migongge"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup
function_start_mysql() {
if [ ! -e "$mysql_sock" ];then
printf "Starting MySQL...\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &
else
printf "MySQL is running...\n"
exit
fi
}
#stop function
function_stop_mysql() {
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...\n"
exit
else
printf "Stoping MySQL...\n"
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql() {
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac
其它的配置可参考配置文件进行修改即可
多实例初始化操作
[root@centos6 3306]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
Installing MySQL system tables...
161209 18:02:17 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
161209 18:02:17 [Note] /application/mysql/bin/mysqld (mysqld 5.5.52-log) starting as process 3336 ...
OK
Filling help tables...
161209 18:02:17 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
161209 18:02:17 [Note] /application/mysql/bin/mysqld (mysqld 5.5.52-log) starting as process 3343 ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/application/mysql/bin/mysqladmin -u root password 'new-password'
/application/mysql/bin/mysqladmin -u root -h centos6 password 'new-password'
Alternatively you can run:
/application/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /application/mysql ; /application/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
初始化成功后,会在数据目录下产生一个数据目录data和一些文件
[root@centos6 3306]# ll /data/3306/data/
total 1136
drwx------. 2 mysql root 4096 Dec 9 18:02 mysql
-rw-rw----. 1 mysql mysql 27693 Dec 9 18:02 mysql-bin.000001
-rw-rw----. 1 mysql mysql 1114546 Dec 9 18:02 mysql-bin.000002
-rw-rw----. 1 mysql mysql 38 Dec 9 18:02 mysql-bin.index
drwx------. 2 mysql mysql 4096 Dec 9 18:02 performance_schema
drwx------. 2 mysql root 4096 Dec 9 18:02 test
另一个实例的初始化请参考上述操作进行,操作过程不再一一介绍
[root@centos6 3307]# ll /data/3307/data/
total 1136
drwx------. 2 mysql root 4096 Dec 9 18:40 mysql
-rw-rw----. 1 mysql mysql 27693 Dec 9 18:40 mysql-bin.000001
-rw-rw----. 1 mysql mysql 1114546 Dec 9 18:40 mysql-bin.000002
-rw-rw----. 1 mysql mysql 38 Dec 9 18:40 mysql-bin.index
drwx------. 2 mysql mysql 4096 Dec 9 18:40 performance_schema
drwx------. 2 mysql root 4096 Dec 9 18:40 test
4 、启动多实例并登录
启动服务
[root@backup 3307]# /data/3306/mysql start
Starting MySQL...
[root@backup 3307]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 19986 mysql 10u IPv4 90967 0t0 TCP *:mysql (LISTEN)
[root@backup 3307]# /data/3307/mysql
start Starting MySQL...
[root@backup 3307]# lsof -i :3307
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 21648 mysql 11u IPv4 92899 0t0 TCP *:opsession-prxy (LISTEN)
检查端口
[root@backup 3307]# netstat -lntup|grep mysql
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 21648/mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 19986/mysqld
登陆多实例数据库
[root@backup ~]# mysql -S /data/3306/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.51-log Source distribution
Copyright (c) 2000, 2016, 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> create database data3306;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| data3306 |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> quit
Bye
[root@backup ~]# mysql -S /data/3307/mysql.sock
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.51 Source distribution
Copyright (c) 2000, 2016, 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.05 sec)
成功登陆,并在3306实例中创建数据库,但是3307实例上查看并没有创建过的数据,说明两个实例是独立的
MySQL数据库入门多实例配置的更多相关文章
- MySQL数据库入门——多实例配置
前面介绍了相关的基础命令操作,所有的操作都是基于单实例的,mysql多实例在实际生产环境也是非常实用的,因为必须要掌握 1.什么是多实例 多实例就是一台服务器上开启多个不同的服务端口(默认3306), ...
- MySQL数据库入门到高薪培训教程(从MySQL 5.7 到 MySQL 8.0)
一.MySQL数据库入门到高薪培训视频教程(从MySQL5.7到MySQL8.0) 本套MySQL学习教程地址: https://edu.51cto.com/course/18034.html 为满足 ...
- Mysql数据库优化技术之配置篇、索引篇 ( 必看 必看 转)
转自:Mysql数据库优化技术之配置篇.索引篇 ( 必看 必看 ) (一)减少数据库访问对于可以静态化的页面,尽可能静态化对一个动态页面中可以静态的局部,采用静态化部分数据可以生成XML,或者文本文件 ...
- PHP连接局域网MYSQL数据库的简单实例
PHP连接局域网MYSQL数据库的简单实例 [php] view plaincopy <?PHP /** * php连接mysql数据库 * by www.jbxue.com */ $conn= ...
- mysql数据库的安装与配置
mysql数据库的安装与配置及workbench的简单使用 mysql数据库社区版下载:https://dev.mysql.com/downloads/installer/ 我这里选的是社区安装版(适 ...
- linux学习之centos(三):mysql数据库的安装和配置
前言:mysql简介 说到数据库,我们大多想到的是关系型数据库,比如mysql.oracle.sqlserver等等,这些数据库软件在windows上安装都非常的方便,在Linux上如果要安装数据库, ...
- linux应用之mysql数据库的安装及配置(centos)
CentOS下Mysql数据库的安装与配置 如果要在Linux上做j2ee开发,首先得搭建好j2ee的开发环境,包括了jdk.tomcat.eclipse的安装(这个在之前的一篇随笔中已经有详细讲 ...
- MySQL数据库的安装与配置(windows)
MySQL是目前最为流行的开放源码的数据库,是完全网络化的跨平台的关系型数据库系统,它是由瑞典MySQLAB公司开发,目前属于Oracle公司.任何人都能从Internet下载MySQL软件,而无需支 ...
- MySQL数据库入门备份数据库
MySQL数据库入门——备份数据库 一提到数据,大家神经都会很紧张,数据的类型有很多种,但是总归一点,数据很重要,非常重要,因此,日常的数据备份工作就成了运维工作的重点中的重点的重点....... ...
随机推荐
- R_Studio(癌症)以等宽类别值、自定义类别值、等频类别值(分为5类)
对“癌症.csv”中的肾细胞癌组织内微血管数进行连续属性的离散化处理 增加“微血管数分类1”属性,取值为等宽类别值(分为5类),增加“微血管数分类2”属性,取值为自定义类别值(0~40,41~60,6 ...
- python环境下安装virtualenv,virtualenvwrapper
在使用 Python 开发的过程中,工程一多,难免会碰到不同的工程依赖不同版本的库的问题: 亦或者是在开发过程中不想让物理环境里充斥各种各样的库,引发未来的依赖灾难. 此时,我们需要对于不同的工程使用 ...
- Zookeeper 选举过程
Zookeeper 选举过程 问题 选举过程 服务器之间是怎么通信的? 答:QuorumCnxManager使用TCP-socket实现选举过程中的连接通信 Leader的选举过程在什么时候实现? L ...
- 设置Apache监听多个端口
1.在配置文件httpd.conf中Listen多个端口 Listen localhost:8033 Listen localhost:8083 ....... 2.在配置文件夹下的extra文 ...
- hdjs---laravel 框架使用hdjs 实现多图上传功能
hdjs---laravel 框架使用hdjs 实现多图上传功能 一.总结 一句话总结: [在网上找hdjs的使用实例]和[能遇见讲hdjs的视频],也是完全搞懂hdjs的不错的方式 1.hdjs中的 ...
- Python学习笔记:类
类可以将数据与函数封装起来,用一个例子解释,先定义一个类: class athlete: def __init__(self,a_name,a_dob=None,a_times=[]): self.n ...
- note:开源许可证之间的区别
最近接触开源项目比较多,关注一下许可证的问题. 饱受诟病的病毒式copyleft就是GPL了.. ref:http://code.csdn.net/news/2819582 ref:http://ww ...
- C++动态链接库实践
参考:https://www.cnblogs.com/Anker/p/3746802.html gcc -fPIC -shared calc.c -o libcalc.so, 编译得到 在linux上 ...
- vue问题二:vue打包时产生的问题
vue项目打包问题:vue中默认的config/index.js的配置的详细理解: 参考文档:https://blog.csdn.net/qq_34611721/article/details/809 ...
- Emacs 浏览网页
Emacs 浏览网页非常方便,还可以忽略掉那些烦人的小广告.特别是在看小说 的时候~ 在之前了解如何通过Emacs浏览网页时,大部分人使用的是w3m,折腾了半天,没能成功.后来无意间发现 ,有EWW ...