我一直在按照手册在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 -uroot。这对我很管用。

其他回答

我遇到了这个非常烦人的问题,并且找到了许多不管用的答案。我遇到的最好的解决方案是完全卸载MySQL并重新安装。重新安装时,您设置了根密码,这就解决了这个问题。

sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean

这段代码是我在其他地方找到的,所以我没有任何功劳。但它确实有效。要在卸载MySQL后安装它,我认为DigitalOcean有一个很好的教程。看看我的要点。

如何在Ubuntu上安装MySQL

注意:对于MySQL 5.7+,请参见Lahiru对这个问题的回答。这包含了更多的最新信息。

对于MySQL < 5.7:

默认root密码为空(即空字符串),而不是root。所以你可以登录为:

mysql -u root

安装完成后,您显然应该更改root密码:

mysqladmin -u root password [newpassword]

在大多数情况下,您还应该在广泛使用数据库之前设置个人用户帐户。

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

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

我所面临的错误是:

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

这是一个端口运行的问题。

默认情况下,MySQL运行在3306端口上。

你可以通过运行来检查

在32位系统中: sudo / opt / lampp / manager-linux.run 在64位系统中: sudo / opt / lampp / manager-linux-x64.run

然后点击Configure按钮。

在我的示例中,端口运行在3307上,我使用了该命令

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

在Mac上,如果你在使用安装时提供的第一个密码登录时遇到问题,也许你可以简单地关闭MySQL进程,然后再尝试。

So:

执行如下命令查看MySQL的PID: mysql | grep -v grep 终止进程: Kill -15[进程id]

可以使用初始密码登录:

mysql -uroot -p

它要求你输入密码。只需输入初始密码。