gpt4 book ai didi

mysql - 无法访问mysql数据库

转载 作者:行者123 更新时间:2023-11-29 12:37:44 25 4
gpt4 key购买 nike

我执行了以下命令来更改数据库密码:

mysql> UPDATE mysql.user SET Password=('root') WHERE User = 'root';
Query OK, 4 rows affected (0.06 sec)
Rows matched: 4 Changed: 4 Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

现在我无法使用密码“root”访问数据库。我收到以下消息:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

谁能帮我解决这个问题吗?

最佳答案

请在您的终端上运行以下命令:

  • 停止 MySQL 守护进程:

    /etc/init.d/mysql stop

  • 安全启动 MySQL:

    sudo/usr/bin/mysqld_safe --skip-grant-tables &

  • 然后您可以开始重置密码:

    为“root@localhost”设置密码 = PASSWORD('yourNewPassword');
    刷新权限;

编辑:
我在自己的计算机上一步步运行命令。您可以关注它们,它们运行成功:

begueradj@begueradj-X71Q:/var/www$ sudo /etc/init.d/mysql stop
[sudo] password for begueradj:
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql stop

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) utility, e.g. stop mysql
mysql stop/waiting
begueradj@begueradj-X71Q:/var/www$ sudo mysqld_safe --skip-grant-tables &
[2] 6035
begueradj@begueradj-X71Q:/var/www$ 141023 10:11:43 mysqld_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect.
141023 10:11:43 mysqld_safe Logging to '/var/log/mysql/error.log'.
141023 10:11:43 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

begueradj@begueradj-X71Q:/var/www$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.37-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2014, 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> 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
mysql> update user set password=PASSWORD("begueradj") where User='root';
Query OK, 4 rows affected (0.02 sec)
Rows matched: 4 Changed: 4 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

您现在可以退出。贝格拉DJ。

关于mysql - 无法访问mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26523327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com