Home > Database > Mysql Tutorial > body text

MySQL多实例讲解

WBOY
Release: 2016-06-07 17:12:40
Original
1249 people have browsed it

mysql多实例,每个MySQL多实例讲解实例的datadir,pid,port,socket应该是不同的,在Unix中,在你启动客户端之前,设置MYSQL_UNIX_P

mysql多实例,每个实例的datadir,pid,port,socket应该是不同的

一、基础,很重要

每个实例应该在自己的datadir下配置my.cnf文件。
首先说下配置文件的查找顺序
第一搜,首先读取/etc/my.cnf
第二搜,$datadir/my.cnf,在data目录下寻找此配置文件,每个实例应该在自己的datadir下配置my.cnf文件。
第三搜,defaultfile=/path/my.cnf 通常写在命令行上,mysqld_safe defaultfile=/tmp/my.cnf &等执行。
第四搜,~/my.cnf 当前用户下的配置文件。


二、为各个实例配置datadir(例子中利用默认实例数据)

停掉mysql默认的服务(防止出现损坏默认实例数据库的情况):service mysql

stop

复制datadir
[root@localhost lib]# cp -r mysql /var/lib/mysql_3301
[root@localhost lib]# cp -r mysql /var/lib/mysql_3302

把mysql设置为owner
[root@localhost lib]# chown -R mysql.mysql mysql_3301
[root@localhost lib]# chown -R mysql.mysql mysql_3302

把mysql设置为文件夹内文件的owner
[root@localhost lib]# cd mysql_3301
[root@localhost mysql_3301]# chown -R mysql.mysql *
[root@localhost mysql_3301]# cd ../mysql_3302
[root@localhost mysql_3302]# chown -R mysql.mysql *

注释:
开始失败的原因在于mysql_3301与mysql_3302文件夹下的文件没有赋权于mysql用

户,,导致错误
cd mysql_3301
chown -R mysql.mysql *
cd ../mysql_3302
chown -R mysql.mysql *

三、配置文件选项:

[root@localhost mysql_3302]# cd /usr/local
[root@localhost local]# vi my_multi.cnf

[mysqld_multi]
mysqld     = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user       = root

[mysqld1]
socket     = /tmp/mysql_3301.sock
port       = 3301
pid-file   = /var/lib/mysql_3301/hostname.pid
datadir    = /var/lib/mysql_3301/
log        = /var/lib/mysql_3301/hostname.log
user       = mysql


[mysqld2]
socket     = /tmp/mysql_3302.sock
port       = 3302
pid-file   = /var/lib/mysql_3302/hostname.pid
datadir    = /var/lib/mysql_3302/
log        = /var/lib/mysql_3302/hostname.log
user       = mysql

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template