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

如果其他答案都不适合您,并且您收到了以下错误:

mysqld_safe Logging to '/var/log/mysql/error.log'.
mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
[1]+  Exit 1                  sudo mysqld_safe --skip-grant-tables

按照以下命令依次执行,直到重置密码:

# Stop your server first
sudo service mysql stop

# Make the MySQL service directory.
sudo mkdir /var/run/mysqld

# Give MySQL permission to work with the created directory
sudo chown mysql: /var/run/mysqld

# Start MySQL, without permission and network checking
sudo mysqld_safe --skip-grant-tables --skip-networking &

# Log in to your server without any password.
mysql -u root mysql


# Update the password for the root user:
UPDATE mysql.user SET authentication_string=PASSWORD('YourNewPasswordBuddy'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';

# If you omit (AND Host='localhost') section, it updates
# the root password regardless of its host

FLUSH PRIVILEGES;
EXIT;

# Kill the mysqld_safe process
sudo service mysql restart

# Now you can use your new password to log in to your server
mysql -u root -p

# Take note for remote access. You should create a remote
# user and then grant all privileges to that remote user

我以root用户($SUDO)安装MySQL,得到了同样的问题

以下是我的解决方法:

sudo cat /etc/mysql/debian.cnf This will show details as: # Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = GUx0RblkD3sPhHL5 socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = debian-sys-maint password = GUx0RblkD3sPhHL5 socket = /var/run/mysqld/mysqld.sock Above we can see the password. But we are just going to use(GUx0RblkD3sPhHL5) that in the prompt. `mysql -u debian-sys-maint -p Enter password: ` Now provide the password (GUx0RblkD3sPhHL5). Now exit from MySQL and log in again as: `mysql -u root -p Enter password: `

现在提供新密码。这是所有。我们有新密码供以后使用。

这对我很管用。

2021年。

回答Ubuntu 20.04 (Focal Fossa)(也可能是其他发行版)。

在四处游荡了几天之后…这些答案对我都没用,我就这么做了,而且成功了!

始终在Bash shell中:

sudo systemctl disable mysql

为了阻止守护进程在启动时启动。

sudo apt purge mysql-server

and

sudo apt purge mysql-community-server*

在那里,它警告你,你将删除配置文件…所以它起作用了!因为他们就是捣乱的人!

sudo autoremove

删除所有遗留的包。

然后重启(也许这是可选的,但我做到了)。 另外,我从MySQL官方网页下载了MySQL -server-8.0:

sudo apt install mysql-server

它正在工作的信号是,当您输入上面的命令时,系统要求您输入根密码。

最后:

mysql -u root -p

还有你之前输入的密码。

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

/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