安装完成后,就是设置配置文件,是mysql 能够运行多个实例。
一下是我们机器上的配置文件my.cnf 的配置
[mysqld_multi]
mysqld =/mysql/mysql/bin/mysqld_safe
mysqladmin= /mysql/mysql/bin/mysqladmin
user =root
password= 7ujm8ik, # 关闭时起作用
# The MySQL server
[mysqld1]
port = 3306
socket =/tmp/mysql.sock
basedir = /mysql/mysql
datadir = /mysql/mysql/data
pid-file = /mysql/mysql/data/muyoufang.pid
log-error = /mysql/mysql/data/muyoufang.err
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
server-id = 1
#打开二进制日志记录功能
log-bin =/mysql/mysql/data/log-bin-files/log-bin #执行日志 mkdir /mysql/mysql/data/log-bin-files/ chownmysql /mysql/mysql/data/log-bin-files/
#忽略数据库复制
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
slow-quer y-log =/mysql/mysql/data/slow_queries.log
long_query_time = 3
skip-name-resolve #跳过反向解析
[mysqld2]
port = 3308
socket =/mysql/mysql/data3308/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
server-id = 2
log-bin=mysql-bin
basedir = /mysql/mysql
datadir = /mysql/mysql/data3308
log-error = /mysql/mysql/data3308/muyoufang.err
pid-file = /mysql/mysql/data3308/muyoufang.pid
下面就已配置 [mysqld2] 为例:
cp -R /mysql/mysql/data cp -R /mysql/mysql/data3308 # 默认的 mysql 数据库复制过来
chown -R mysql /mysql/mysql/data3308 # 该目录改为 mysql 管理权
export PATH=/usr/local/mysql/bin:$PATH
使用如下参数来启动 mysqld_multi : ( 注:该命令在 mysql 的 bin 目录中,根据上面所提到 ./configure --prefix=/usr/bin/mysql ,所以该文件应该在 /usr/bin/mysql/bin ,这得根据你安装时所指定的路径 ) 。
mysqld_multi [options] [GNR[,GNR]...]
1.mysqld_multi.server stop 8. 对单台数据库的启动和关闭
语法: mysqld_multi [options] {start|stop|report} [GNR[,GNR]…]
如对 mysqld1 的启动和关闭,可以通过 mysqld_multi 来操作
启动: mysqd_multi start 1 配置中的 [mysqld2] 后面的数字
关闭: mysqd_multi stop 1
也可以同时启动和关闭多个 MySQL 数据库实例
启动: mysqd_multi start 1-3
关闭: mysqd_multi stop 1-3
停止服务器命令
./bin/mysqladmin -u root -p7ujm8ik, -S /mysql/mysql/data3308/mysql.sock shutdown
关闭: mysqd_multi stop 1-3
mysqld_multi stop 执行条件需要授权
授权关闭
grant shutdown on *.* to 'root'@'localhost' identified by'7ujm8ik,'
或者全部授权
grant all on *.* to 'root'@'localhost' identified by'7ujm8ik,'
多端口登陆
mysql -u root -S /tmp/mysql.sock -proot_password
----------------------------------------------------------------------------------------------------------------------------------
多my.cnf 文件
进入 mysql 安装目录得 bin
./mysql_install_db --datadir=/mysql/mysql/data3307
或者 cp -R /mysql/mysql/data /mysql/mysql/data3308
cp /mysql/mysql/support-files/my-medium.cnf/mysql/mysql/data3308/my.cnf
[client]
#password = your_password
port = 3308
socket = /mysql/mysql/data3308/mysql.sock
[mysqld]
port = 3308
socket =/mysql/mysql/data3308/mysql.sock
basedir = /mysql/mysql
datadir = /mysql/mysql/data3308
log-error = /mysql/mysql/data3308/muyoufang.err
pid-file = /mysql/mysql/data3308/muyoufang.pid
停止所有的 mysql 服务重新启动
./bin/mysqld_safe --defaults-extra-file=/mysql/mysql/data3307/my.cnf&
shutdown server
./mysqladmin -u root -p -S /mysql/mysql/data3307/mysql.sock shutdown
启动 mysql 时如果下列报错信息:
[root@localhost ~]# Warning: World-writable config file'/var/lib/mysql_8305/my.cnf' is ignored
Warning: World-writable config file'/var/lib/mysql_8305/my.cnf' is ignored
刚创建的
原因: my.cnf 的读取权限太大了,不允许 World-writable
解决方法:
sudo chmod 644 / mysql/mysql/data3307/my.cnf