5、准备配置文件
1
|
mysqld_multi --example > /data/multi.cnf #提供多配置文件模板
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
vim /data/multi.cnf #修改模板,这里比较简易
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = root
#这个用户应该有关机权限,然后没有其他的权限。建议创建一个通用的,multi_admin用户控制其它的MySQL用户,这里有个例子
#GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'password'
[mysqld1]
socket = /tmp/mysql.sock1
port = 3306
pid-file = /data/3306/mysql.pid
datadir = /data/3306/data
[mysqld2]
socket = /tmp/mysql.sock2
port = 3307
pid-file = /data/3307/mysql.pid
datadir = /data/3307/data
#language = /usr/local/mysql/share/mysql/english
#user = unix_user1
[mysqld3]
#mysqld = /path/to/mysqld_safe
#ledir = /path/to/mysqld-binary/
#mysqladmin = /path/to/mysqladmin
socket = /tmp/mysql.sock3
port = 3308
pid-file = /data/3308/mysql.pid
datadir = /data/3308/data
#language = /usr/local/mysql/share/mysql/swedish
#user = unix_user2
|
以上是简易的配置文件。这个配置文件只能让MySQL启动起来。
6、启动MySQL
1
2
3
4
5
|
mysqld_multi --defaults-file=/data/multi.cnf start 1,2,3
ss -tnl #查看监听端口
LISTEN 0 50 *:3306 *:*
LISTEN 0 50 *:3307 *:*
LISTEN 0 50 *:3308 *:*
|
7、登录mysql与一些安全措施
1
|
mysql -S /tmp/mysql.sock1 #指定socket登录
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.04 sec)
mysql> select User,Host from mysql.user;
+------+-----------+
| User | Host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | node1 |
| root | node1 |
+------+-----------+
6 rows in set (0.01 sec)
mysql> delete from mysql.user where User='';
Query OK, 2 rows affected (0.00 sec)
mysql> delete from mysql.user where Host='::1';
Query OK, 1 row affected (0.00 sec)
mysql> delete from mysql.user where Host='node1';
Query OK, 1 row affected (0.00 sec)
|
其余的操作类似,就不在演示
8、关闭MySQL
1
2
3
|
mysqladmin -S /tmp/mysql.sock1 shutdown 建议使用
musqld_multi --defaults-file stop [#,#]
killall mysqld 不建议使用
|
本文转自 tianya1993 51CTO博客,原文链接:http://blog.51cto.com/dreamlinux/1837089,如需转载请自行联系原作者