我一直在按照手册在Ubuntu上安装软件套件。我完全不了解MySQL。我已经在我的Ubuntu上完成了以下安装。

sudo apt-get update
sudo apt-get install mysql-server-5.5
sudo apt-get install mysql-client-5.5
sudo apt-get install mysql-common
sudo apt-get install glade
sudo apt-get install ntp

然后我做了

cd ~/Desktop/iPDC-v1.3.1/DBServer-1.1
mysql -uroot -proot <"Db.sql"

我最终得到以下错误消息。

错误1045(28000):拒绝访问用户'root'@'localhost'(使用密码:YES)

我该如何修复它并继续?


当前回答

我可以通过执行这条语句来解决这个问题

sudo dpkg-reconfigure mysql-server-5.5

这将改变根密码。

其他回答

一句话就解决了我的问题。

sudo dpkg-reconfigure mysql-server-5.5

在我的情况下,我试图传递一个shell命令到docker容器。在这种情况下,只有第一个词被解释。确保你没有在运行:

mysql

相对于:

mysql -uroot -ppassword schemaname

也许可以试着引用:

'mysql -uroot -ppassword schemaname'

如果你把MySQL作为Docker镜像的一部分(比如在6606端口上),而Ubuntu安装(在3306端口上),指定端口是不够的:

mysql -u root -p -P 6606

将把:

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

因为默认情况下它试图连接到localhost,指定您的本地IP地址可以修复这个问题:

mysql -u root -p -P 6606 -h 127.0.0.1

答案可能听起来很傻,但在浪费了几个小时的时间后,我是这样做到的:

mysql -u root -p

我收到了错误信息

错误1045(28000):拒绝访问用户'root'@'localhost'(使用密码:YES)

尽管我输入了正确的密码(你第一次安装MySQL时得到的临时密码)。

当密码提示闪烁时,我输入了密码。

你必须重设密码!Mac OS X(已测试并正在运行)和Ubuntu的步骤:

停止使用MySQL

sudo service mysql stop

or

sudo /usr/local/mysql/support-files/mysql.server stop

以安全模式启动:

sudo mysqld_safe --skip-grant-tables --skip-networking

(上面一行是整个命令)

这将是一个持续的命令,直到进程结束,所以打开另一个shell/终端窗口,登录没有密码:

mysql -u root

mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

根据@IberoMedia的评论,对于新版本的MySQL,该字段被称为authentication_string:

mysql> UPDATE mysql.user SET authentication_string =PASSWORD('password') WHERE User='root';

启动MySQL使用:

sudo service mysql start

or

sudo /usr/local/mysql/support-files/mysql.server start

你的新密码是“password”。

注意:对于MySQL > 5.7版本,请尝试以下操作:

update mysql.user set authentication_string='password' where user='root';