这里主要说明不同登录方式,对应不同的用户,
譬如带上-h加ip地址参数,若是ip地址,用户就是xxx@%或者xxx@主机名,
若是带上-hlocalhost参数,则用户是xxx@localhost,若不带-h参数,则用户也是xxx@localhost,
但何时是xxx@127.0.0.1呢?
一般我们创建用户有4类:
1、xxx@localhost
2、xxx@127.0.0.1
3、xxx@主机名
4、xxx@%
由于mysql虽然用户名相同,但实际上是不同的用户,所以当出现什么用户没有权限时,
首先要用select current_user确定当前是哪个用户,再确定其是否有权限。
下面带-h加ip地址,要么是xxx@%,要么是xxx@主机名
root@laojiang1:~> mysql -ulaojiang -ppassword -h10.10.10.1 -Dlaojiang;
mysql> select current_user;
+--------------+
| current_user |
+--------------+
| laojiang@% |
+--------------+
root@laojiang2:~> mysql -ulaojiang -ppassword -h10.10.10.2 -Dlaojiang;
mysql> select current_user;
+---------------------+
| current_user |
+---------------------+
| laojiang@laojiang2 |
+---------------------+
下面不带-h或者带-hlocalhost,用户都是xxx@localhost
root@laojiang1:~> mysql -ulaojiang -ppassword -hlocalhost -Dlaojiang;
mysql> select current_user;
+---------------------+
| current_user |
+---------------------+
| laojiang@localhost |
+---------------------+
root@laojiang1:~> mysql -ulaojiang -ppassword -Dlaojiang;
mysql> select current_user;
+---------------------+
| current_user |
+---------------------+
| laojiang@localhost |
+---------------------+
下面带-h主机名,用户可能是xxx@%或者xxx@主机名
root@laojiang1:~> mysql -ulaojiang -ppassword -hlaojiang1 -Dlaojiang;
mysql> select current_user;
+--------------+
| current_user |
+--------------+
| laojiang@% |
+--------------+
root@laojiang2:~> mysql -ulaojiang -ppassword -hlaojiang2 -Dlaojiang;
mysql> select current_user;
+---------------------+
| current_user |
+---------------------+
| laojiang@laojiang2 |
+---------------------+
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29911917/viewspace-1280955/,如需转载,请注明出处,否则将追究法律责任。