首先让我提一下,我已经看了很多建议的问题,但没有找到相关的答案。这就是我正在做的。
我连接到Amazon EC2实例。我可以用这个命令登录MySQL根目录:
mysql -u root -p
然后我用host %创建了一个新的用户帐单
CREATE USER 'bill'@'%' IDENTIFIED BY 'passpass';
授予用户bill的所有权限:
grant all privileges on *.* to 'bill'@'%' with grant option;
然后我退出root用户,尝试用bill登录:
mysql -u bill -p
输入正确的密码并得到以下错误:
错误1045(28000):用户“账单”@“localhost”(使用密码:YES)的访问被拒绝
当你的密码包含一些特殊字符,如@,$等,也会发生这种情况。
为了避免这种情况,你可以把password用单引号括起来:
$ mysql -usomeuser -p's0mep@$$w0Rd'
或者在输入时不用密码。请留空,然后在终端要求时输入。这是推荐的方法。
$ mysql -usomeuser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 191
Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
MySQL account names consist of a user name and a host name, The name 'localhost' in host name indicates the local host also You can use the wildcard characters “%” and “_” in host name or IP address values. These have the same meaning as for pattern-matching operations performed with the LIKE operator. For example, a host value of '%' matches any host name, whereas a value of '%.mysql.com' matches any host in the mysql.com domain. '192.168.1.%' matches any host in the 192.168.1 class C network.
以上只是介绍:
实际上,用户“bill”@“localhost”和“bill”@“%”是不同的MySQL帐户,因此两者都应该使用自己的身份验证细节,如密码。
欲了解更多信息,请参阅http://dev.mysql.com/doc/refman//5.5/en/account-names.html
百分号表示所有ip,所以localhost是多余的…本地主机不需要第二条记录。
实际上有,'localhost'在mysql中是特殊的,它意味着通过unix套接字(或windows上的命名管道)连接,而不是TCP/IP套接字。使用%作为主机不包括'localhost'
MySQL用户帐户有两个组成部分:用户名和主机名。用户名标识用户,主机名指定用户可以从哪些主机连接。用户名和主机名的组合:
< user_name >的@ < host_name >的
您可以为主机名指定特定的IP地址或地址范围,或者使用百分比字符(“%”)使该用户能够从任何主机登录。
注意,用户帐户是由用户名和主机名同时定义的。例如,“root”@“%”与“root”@“localhost”是不同的用户帐户。
如果MySQL运行在不区分大小写的操作系统(如Windows)上,也可能发生这种情况。
例:我发现尝试使用这些凭据连接到数据库失败:
mysql>授予数据库ev105的select权限。*到'specialuser',标识为's3curepa5wrd';
$ mysql -specialuser' -p's3curepa5wrd' -h10.61.130.89 databaseV105
错误1045(28000):拒绝访问用户'specialuser'@'10.0.1.113'(使用密码:YES)
但是,这成功了:
Mysql >授予select权限*到'specialuser',标识为's3curepa5wrd';
mysql ' - h10300,300,400 database105 -p
输入密码: