MySQL单机多实例配置
测试环境: 操作系统 CentOS 6.4 x86 MySQL 5.5.38 1、什么是MySQL多实例? MySQL多实例就是在一台机器上开启多个不同的服务端
测试环境:
操作系统 CentOS 6.4 x86
MySQL 5.5.38
1、什么是MySQL多实例?
MySQL多实例就是在一台机器上开启多个不同的服务端口(如:3306,3307,3308),运行多个MySQL服务进程,通过不同的socket监听不同的服务端口来提供各自的服务。各个实例之间是相互独立的,每个实例的datadir, port, socket, pid都是不同的。
2、MySQL多实例的特点
•有效利用服务器资源,当单个服务器资源有剩余时,可以充分利用剩余的资源提供更多的服务。
•资源互相抢占问题,当某个服务实例服务并发很高时或者开启慢查询时,会消耗更多的内存、CPU、磁盘IO资源,导致服务器上的其他实例提供服务的质量下降。
3、应用场景
•采用了数据伪分布式架构的原因,而项目启动初期又不一定有那多的用户量,为此先一组物理数据库服务器,但部署多个实例,方便后续迁移;
•为规避mysql对SMP架构不支持的缺陷,使用多实例绑定处理器的办法,把不同的数据库分配到不同的实例上提供数据服务;
•一台物理数据库服务器支撑多个数据库的数据服务,为提高mysql复制的从机的恢复效率,采用多实例部署;
•已经为双主复制的mysql数据库服务器架构,想部分重要业务的数据多一份异地机房的热备份,而mysql复制暂不支持多主的复制模式,且不给用户提供服务,为有效控制成本,会考虑异地机房部署一台性能超好的物理服务器,甚至外加磁盘柜的方式,为此也会部署多实例;
•传统游戏行业的MMO/MMORPG,以及Web Game,每一个服都对应一个数据库,而可能要做很多数据查询和数据订正的工作,,为减少维护而出错的概率,也可能采用多实例部署的方式,按区的概念分配数据库;
4、约定
1、将所有的安装文件、配置文件、数据目录全部放存/mydata/data目录中,便于今后实现快速迁移、整体备份和快速复制;
2、在一台服务器上配置2个MySQL实例,分别绑定在3306、3307端口。
3、实例均采用my-medium.cnf 配置文件;我们可以根据实际需求定制各个实例的my.cnf配置。
my.cnf配置文件有两种方案:
1.
多个实例共用同一个my.cnf配置文件中,利用[mysqld1]、[mysqld2]、[mysqld*]标签实现不同实例的差异化配置;
2.
每一个实例单独一个my.cnf配置文件
Ubuntu 14.04下安装MySQL
《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF
Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL
Ubuntu 14.04下搭建MySQL主从服务器
Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群
Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb
--------------------------------------------------------------------------------
第一种方案:每一个实例单独一个my.cnf配置文件
datadir: /mydata/data/3306
/mydata/data/3307
my.cnf: /mydata/data/3306/my.cnf
/mydata/data/3307/my.cnf
5、安装MySQL(通用二进制方式)
1、创建mysql用户和组
[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -r -g mysql -s /sbin/nologin mysql
2、目录规划
我们为每个实例单独创建一个目录:3306, 3307
[root@localhost ~]# mkdir -pv /mydata/data/330{6,7}
mkdir: created directory `/mydata/data/3306'
mkdir: created directory `/mydata/data/3307'
[root@localhost ~]# tree /mydata/data/
/mydata/data/
|-- 3306
`-- 3307
3、解压
[root@localhost ~]# tar xf mysql-5.5.38-linux2.6-i686.tar.gz -C /usr/local/src
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv src/mysql-5.5.38-linux2.6-i686/ mysql
create symbolic link `mysql' to `src/mysql-5.5.38-linux2.6-i686/'
4、提供配置文件,并编辑
[root@localhost local]# cd mysql
[root@localhost mysql]# cp support-files/my-medium.cnf /mydata/data/3306/my.cnf
[root@localhost mysql]# cp support-files/my-medium.cnf /mydata/data/3307/my.cnf
# 这里是实验环境,所以简单配置。请各位看官根据实际需求调整
###3306
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql_3306.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql_3306.sock
pid-file = /mydata/data/3306/mysql.pid
user = mysql
basedir = /usr/local/mysql
datadir = /mydata/data/3306
###########################################################
###3307
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3307
socket = /tmp/mysql_3307.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3307
socket = /tmp/mysql_3307.sock
pid-file = /mydata/data/3307/mysql.pid
user = mysql
basedir = /usr/local/mysql
datadir = /mydata/data/3307
5、修改数据目录的属主、属组
[root@localhost mysql]# chown -R mysql:mysql /mydata/data/3306
[root@localhost mysql]# chown -R mysql:mysql /mydata/data/3307
6、把mysql/bin目录添加到PATH
[root@localhost mysql]# vi /etc/profile.d/mysql.sh
# 添加
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost mysql]# . /etc/profile.d/mysql.sh
7、初始化
# 初始化 实例1
[root@localhost mysql]# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/data/3306 --user=mysql
# 初始化 实例2
[root@localhost mysql]# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/data/3307 --user=mysql
8、启动/关闭 实例
这里有一个问题,每个实例如何读取各自的my.cnf配置文件呢? 我们需要手动指定
•
/usr/local/mysql/bin/mysqld_safe
•
--defaults-file 手动指定配置文件

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.
