使用 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)
好像是主机名的问题,具体因为啥不太清楚,请教一下大家,谢谢
Try this one below!
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:
3 rows in set (0.00 sec)