首先让我提一下,我已经看了很多建议的问题,但没有找到相关的答案。这就是我正在做的。

我连接到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)的访问被拒绝


当前回答

我遇到了同样的错误。失败的设置如下:

define("HOSTNAME", "localhost");
define("HOSTUSER", "van");
define("HOSTPASS", "helsing");
define("DBNAME", "crossbow");
$connection = mysqli_connect(HOSTNAME, HOSTUSER, HOSTPASS);

下面编辑的设置是让它工作的一个。注意到区别了吗?

define('HOSTNAME', 'localhost');
define('HOSTUSER', 'van');
define('HOSTPASS', 'helsing');
define('DBNAME', 'crossbow');
$connection = mysqli_connect(HOSTNAME, HOSTUSER, HOSTPASS);

区别在于双引号。与Java相比,它们在PHP中似乎相当重要,它们在转义字符、设置url以及现在向函数传递参数时都有影响。它们更漂亮(我知道),但总是尽可能多地使用单引号,如果必要的话,可以在其中嵌套双引号。

当我在Linux机器上而不是Windows环境上测试应用程序时,出现了这个错误。

其他回答

好吧,我不确定,但可能是mysql安装目录中的my.cnf文件是罪魁祸首。 注释掉这一行,问题就可以解决了。

bind-address = 127.0.0.1

操作系统:windows

我的错误信息是:

MySQL ERROR 1045(28000):用户'root'@'localhost'(使用密码:YES)被拒绝访问

我的原因是,我没有打开cmd与管理员权限。

所以我的解决方案是作为管理员打开cmd,然后它就工作了。

如果您忘记密码或想修改密码。你可以遵循以下步骤:

1 :stop your mysql [root@maomao ~]# service mysqld stop Stopping MySQL: [ OK ] 2 :use “--skip-grant-tables” to restart mysql [root@mcy400 ~]# mysqld_safe --skip-grant-tables [root@cy400 ~]# Starting mysqld daemon with databases from /var/lib/mysql 3 : open a new window and input mysql -u root [root@cy400 ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. 4 : change the user database mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed 5 : modify your password your new password should be input in "()" mysql> update user set password=password('root123') where user='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 6 : flush mysql> flush privileges; 7: quit mysql> quit Bye 8: restart mysql [root@cy400 ~]# service mysqld restart; Stopping MySQL: [ OK ] Starting MySQL: [ OK ]

宾果!你可以用用户名和新密码连接你的数据库:

[root@cy400 ~]# mysql -u root -p <br>
Enter password: admin123 <br>
Welcome to the MySQL monitor.  Commands end with ; or \g. <br>
Your MySQL connection id is 2 <br>
Server version: 5.0.77 Source distribution <br>
Type 'help;' or '\h' for help. Type '\c' to clear the buffer. <br>
mysql> quit <br>
Bye

我希望你在mysql中删除debian-sys- maintenance用户没有造成更大的损害

让你的mysql守护进程正常运行。启动mysql客户端,如下所示

mysql -u debian-sys-maint -p

在另一个终端,cat /etc/mysql/debian.cnf文件。该文件包含密码;当提示输入密码时,粘贴该密码。

http://ubuntuforums.org/showthread.php?t=1836919

这可能只适用于少数人,但事实就是这样。不要用感叹号!在你的密码里。

我做到了,并使用MariaDB得到了上述错误。当我把它简化成数字和字母时,它是可行的。其他字符,如@和$工作得很好-我在同一实例的不同用户中使用了这些字符。

这个地址的第五次回复让我找到了解决办法。