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

我该如何修复它并继续?


当前回答

在最近的MySQL版本中,MySQL中没有任何密码。用户表。

所以你需要执行ALTER USER。将这一行命令放入文件中。

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

并以init文件的形式执行(以root或mysql用户):

mysqld_safe --init-file=/home/me/mysql-init &

MySQL服务器需要停止才能启动mysqld_safe。

另外,加载这个init文件的AppArmor权限可能也有问题。阅读更多在AppArmor和MySQL。

其他回答

我知道已经很晚了。 我在弹簧引导应用程序中遇到了这个问题。

我通过使用默认值解决了这个问题,让我解释一下。

当我使用hibernate时,我使用了这个属性

<物业name =“连接用户。root > < /物业>

即connection.user

现在,我尝试在spring-boot应用程序中使用相同的方法。

spring.datasource.user

我得到这个错误。

解决方案是 spring.datasource.username

当您的密码丢失时就会发生这种情况。

忘记密码时的修改步骤:

Stop MySQL Server (on Linux): sudo systemctl stop mysql Start the database without loading the grant tables or enabling networking: sudo mysqld_safe --skip-grant-tables --skip-networking & The ampersand at the end of this command will make this process run in the background, so you can continue to use your terminal and run mysql -u root (as root). It will not ask for a password. If you get error like as below: 2018-02-12T08:57:39.826071Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists. mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) [1]+ Exit 1 Make MySQL service directory. sudo mkdir /var/run/mysqld Give MySQL user permission to write to the service directory. sudo chown mysql: /var/run/mysqld Run the same command in step 2 to run MySQL in background. Run mysql -u root. You will get the MySQL console without entering a password. Run these commands FLUSH PRIVILEGES; For MySQL 5.7.6 and newer ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; For MySQL 5.7.5 and older SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password'); If the ALTER USER command doesn't work use: UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHERE User = 'root' AND Host = 'localhost'; Now exit To stop the instance started manually: sudo kill `cat /var/run/mysqld/mysqld.pid` Restart MySQL sudo systemctl start mysql

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

mysql -u root -p

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

Enter password:

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

请阅读官方文档:MySQL:如何重置Root密码

如果您可以访问终端:

MySQL 5.7.6及以上版本:

mysql

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5及以前版本:

mysql

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

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

mysql -u root -p

我收到了错误信息

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

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

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