我一直在按照手册在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)

我该如何修复它并继续?


当前回答

如果问题仍然存在,请尝试强制修改密码:

/etc/init.d/mysql stop

mysqld_safe --skip-grant-tables &

mysql -u root

设置新的MySQL root用户密码:

use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit;

停止MySQL服务器:

/etc/init.d/mysql stop

启动MySQL服务器并测试它:

mysql -u root -p

其他回答

我使用的是mysql-5.7.12-osx10.11-x86_64。dmg在Mac OS X上。

安装过程会自动为root用户设置一个临时密码。你应该保存密码。密码不可恢复。

按照说明操作:

Go to cd /usr/local/mysql/bin/ Enter the temporary password (which would look something like, "tsO07JF1=>3") You should get the mysql> prompt. Run, SET PASSWORD FOR 'root'@'localhost' = PASSWORD('{YOUR_PASSWORD}'); If you wish to set your password: "root" then the command would be, SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root'); Run ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; Run exit Run ./mysql -u root -p Type your password. In my case I would type, "root" (without quote) That's all.

为了方便起见,您应该在PATH环境变量中添加“/usr/local/mysql/bin”。

现在你可以在任何地方输入。/mysql -u root -p,然后输入密码,你会得到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';

我在Ubuntu 18.04 (Bionic Beaver) LTS和MySQL服务器版本5.7.27-0ubuntu0.18.04.1 (Ubuntu)时遇到了这个问题。

我的解决方案是(以root身份运行sudo -i):

mysql <<-EOSQL
  use mysql;
  update user set plugin="mysql_native_password" where User='root';
  FLUSH PRIVILEGES;
EOSQL

mysqladmin -u root password new_pw

在终端输入:

mysql -u root -p

然后它会问你密码。

我最近也遇到了同样的问题,但就我而言,我记得我的密码很好,但它一直给我同样的错误。我尝试了很多方法,但是没有一个有用。然后我试了一下:

mysql -u root -p

然后它会要求你输入密码,就像这样

Enter password:

然后我输入了我用的密码。这是所有。