docker - MySQL 报错:Access denied for user 'xxx'@'localhost'
迷茫
迷茫 2017-04-17 15:03:55
0
4
652

使用 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)

好像是主机名的问题,具体因为啥不太清楚,请教一下大家,谢谢

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(4)
巴扎黑

Try this one below!

mysql --host=db -u root -p 
黄舟

First use the root account to check if newuser has permission to connect to localhost

小葫芦

localhost in mysql refers to the local machine, not the machine name

巴扎黑

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)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template