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

我该如何修复它并继续?


当前回答

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

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

其他回答

在终端输入:

mysql -u root -p

然后它会问你密码。

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

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

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

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

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

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

即connection.user

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

spring.datasource.user

我得到这个错误。

解决方案是 spring.datasource.username

默认情况下,密码为空,因此您必须按照以下步骤修改密码。

连接MySQL

root# mysql

Use mysql

mysql> update user set password=PASSWORD('root') where User='root';

最后,重新加载特权:

mysql> flush privileges;
mysql> quit

我使用的是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>提示。