使用 MySQL 创建一个新的用户,理论上是这样的,
先用 root 用户登录,然后CREATE USER ‘newuser’@‘localhost' IDENTIFIED BY '12345';
用 docker 搭建的开发环境,数据库主机的名字是 db 不是 localhost,
于是 CREATE USER ‘newuser’@‘db' IDENTIFIED BY '12345';
然后我登录遇到问题了:mysql -u newuser -p
输入密码后提示Access denied for user 'newuser'@'localhost' (using password: YES)
好像是主机名的问题,具体因为啥不太清楚,请教一下大家,谢谢
黄舟2017-04-17 15:05:55
First use the root account to check if newuser has permission to connect to localhost
巴扎黑2017-04-17 15:05:55
The problem was solved. I asked a master who is familiar with docker for advice:
It needs to be created like this:
CREATE USER 'newuser'@'%' IDENTIFIED BY '12345';
View users and hosts: select host, user, password from mysql.user;
Return something like this:
host | user | password |
---|---|---|
% | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
% | app | *E56A114692FE0DE073F9A1DD68A00EEB9703F3F1 |
% | newuser | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
3 rows in set (0.00 sec)