mysql用户本机登录方式对应的用户

这里主要说明不同登录方式,对应不同的用户,
譬如带上-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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29911917/viewspace-1280955/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值