服务器运维LinuxMySQL
2025-04-03 15:16阅读:49评论:0
Ubuntu安装MySQL
如果遇到ERROR 1698 (28000): Access denied for user 'root'@'localhost' 解决方案 参考(5 Answers):<https://stackoverflow.com/questions/39281594/error-1698-28000-ac
1
2
3
4
#sudo apt-get -y install mysql-server mysql-client// 登录MySQL,MySQL的root用户密码默认空#sudo mysql -u root _PROTECTED0__ 解决方案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Basically means that: db_users using it, will be "auth" by the system user credentias. You can see if your root user is set up like this by doing the following: $ sudo mysql -u root # I had to use "sudo" since is new installation mysql> USE mysql;mysql> SELECT User, Host, plugin FROM mysql.user; +------------------+-----------------------+| User | plugin |+------------------+-----------------------+| root | auth_socket || mysql.sys | mysql_native_password || debian-sys-maint | mysql_native_password |+------------------+-----------------------+As you can see in the query, the root user is using the auth_socket plugin There are 2 ways to solve this: You can set the root user to use the mysql_native_password pluginYou can create a new db_user with you system_user (recommended)Option 1: $ sudo mysql -u root # I had to use "sudo" since is new installation mysql> USE mysql;mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';mysql> FLUSH PRIVILEGES;mysql> exit; $ service mysql restartOption 2: (replace YOUR_SYSTEM_USER with the username you have) $ sudo mysql -u root # I had to use "sudo" since is new installation mysql> USE mysql;mysql> CREATE USER 'YOUR_SYSTEM_USER'@'localhost' IDENTIFIED BY '';mysql> GRANT ALL PRIVILEGES ON *.* TO 'YOUR_SYSTEM_USER'@'localhost';mysql> UPDATE user SET plugin='auth_socket' WHERE User='YOUR_SYSTEM_USER';mysql> FLUSH PRIVILEGES;mysql> exit; $ service mysql restartRemember that if you use option #2 you'll have to connect to mysql as your system username (mysql -u YOUR_SYSTEM_USER) Note: On some systems (e.g., Debian stretch) 'auth_socket' plugin is called 'unix_socket', so the corresponding SQL command should be: UPDATE user SET plugin='unix_socket' WHERE User='YOUR_SYSTEM_USER'; _PROTECTED0_ 到此MySQL的root用户密码也是空
PROTECTED1__ 格式格式:mysqladmin -u用户名 -p旧密码 password 新密码
\$ mysqladmin -uroot -p password 123456
- 执行上面命令会提示输入密码(原密码),直接按回车键