mysql> grant shutdown on *.* to 'multiadmin'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
-----------------------------------------
最后验证的时候,发现直接将password添加到[mysqld_multi]中,并不能关闭实例
# grep "password" -B 5 multi.cnf [mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld_safe mysqladmin = /usr/local/mysql/bin/mysqladmin #用来做关闭mysql使用 user =multiadmin password=123456
[root@spark01 ~]# mysqld_multi --defaults-file=/root/multi.cnf start
[root@spark01 ~]# mysqld_multi --defaults-file=/root/multi.cnf report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is running
[root@spark01 ~]# mysqld_multi --defaults-file=/root/multi.cnf stop
[root@spark01 ~]# mysqld_multi --defaults-file=/root/multi.cnf report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is running
[root@spark01 ~]# mysqld_multi --defaults-file=/root/multi.cnf --password=123456 stop
[root@spark01 ~]# mysqld_multi --defaults-file=/root/multi.cnf report
Reporting MySQL servers
MySQL server from group: mysqld3306 is not running
MySQL server from group: mysqld3307 is not running
直接使用stop并不能关闭实例,但是在客户端指定password却又可以,用mysqladmin关闭又没问题。
直接使用stop关闭,multi日志报如下信息:
Warning: Using a password on the command line interface can be insecure. ^G/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'multiadmin'@'localhost' (using password: YES)'
当然,[mysqld_multi]中除了用mysqld_safe启动mysql实例外,也可直接通过mysqld,这时[mysqld3306],[mysqld3307]中需指定user=mysql。
------------------------------------------------
在验证的过程中,发现给multiadmin如下授权
GRANT ALL PRIVILEGES ON *.* TO 'multiadmin'@'%' IDENTIFIED BY PASSWORD
%并不包括localhost
验证如下:
mysql> select user,host,password from mysql.user; +------------+-----------+-------------------------------------------+ | user | host | password | +------------+-----------+-------------------------------------------+ | root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | root | spark01 | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | spark01 | | | multiadmin | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +------------+-----------+-------------------------------------------+
在本机用multiadmin登录
# mysql --socket=/sales3307/mysql/run/mysql.sock -umultiadmin -p123456 Warning: Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'multiadmin'@'localhost' (using password: YES)
但是不输入密码却又能登录,只是没有任何权限
[root@spark01 ~]# mysql --socket=/sales3307/mysql/run/mysql.sock -umultiadmin Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.6.28-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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> \s -------------- mysql Ver 14.14 Distrib 5.6.28, for linux-glibc2.5 (x86_64) using EditLine wrapper Connection id: 8 Current database: Current user: multiadmin@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.6.28-log MySQL Community Server (GPL) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /sales3307/mysql/run/mysql.sock Uptime: 32 min 17 sec Threads: 1 Questions: 22 Slow queries: 0 Opens: 74 Flush tables: 1 Open tables: 67 Queries per second avg: 0.011 -------------- mysql> select user(); +----------------------+ | user() | +----------------------+ | multiadmin@localhost | +----------------------+ 1 row in set (0.00 sec) mysql> select user,host from mysql.users; ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'users'
这个其实与上面权限表中的user为空,host为localhost有关。