MySQL上的用户'user'@'localhost'访问被拒绝

时间:2012-08-05 18:40:18

标签: mysql database mysql-error-1045

我正在尝试将我连接到数据库MySQL服务器,但控制台显示 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 我不知道为什么。请帮我。在我的文件my.cnf中,我有类似的内容,

[mysqld]
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

# To allow mysqld to connect to a MySQL Cluster management daemon, uncomment
# these lines and adjust the connectstring as needed.
#ndbcluster
#ndb-connectstring="nodeid=4;host=localhost:3306"

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[ndbd]
# If you are running a MySQL Cluster storage daemon (ndbd) on this machine,
# adjust its connection to the management daemon here.
# Note: ndbd init script requires this to include nodeid!
connect-string="nodeid=2;host=localhost:3306"

[ndb_mgm]
# connection string for MySQL Cluster management tool
connect-string="host=localhost:3306"

[client]
socket=/tmp/mysql.sock

enter image description here

感谢。

2 个答案:

答案 0 :(得分:3)

如果你真的不记得通行证,你可以将skip_grant_tables添加到[mysqld]的{​​{1}}部分,重启服务器,它会让你进入而没有密码,然后您可以通过更新my.cnf表来更改密码,然后重新启动mysql,删除mysql.user选项。

答案 1 :(得分:0)

-p标志表示密码要求。输入您键入的请求密码后应该有第二个提示。例如:

$ mysql -u root -p
$ Enter password: 

然后输入密码。