当前位置:网站首页>【Linux】【Mysql】ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘
【Linux】【Mysql】ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘
2022-06-28 03:18:00 【amRobinson】
工具:
mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64)
问题描述:
Ubuntu在安装完成mysql后,无法直接通过mysql -u root -p命令登录mysql,出现如下错误:ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’
解决方法:
Ubuntu linux下安装新版本mysql,安装时root密码是随机的,因此会出现上述错误。
第一步,登录mysql
既然我们无法通过root用户进入MySQL,那我们就只能通过其他用户登录MySQL了。在我们下载安装MySQL的时候系统给我们创建了一个用户。打开 /etc/mysql/debian.cnf如下。
[email protected]:~$ sudo cat /etc/mysql/debian.cnf
[email protected]:~$ sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = 0NBFUVaaRF8KiZBD
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = 0NBFUVaaRF8KiZBD
socket = /var/run/mysqld/mysqld.sock
我们找到client的user和password,然后在终端输入mysql -u debian-sys-maint -p
然后回车输入 password的内容。这样就进入了MySQL了,如图:
[email protected]:~$ mysql -u debian-sys-maint -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
第二步,查看user表
在mysql中输入:
select user, plugin from mysql.user,
结果如下:
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| root | auth_socket |
| mysql.session | mysql_native_password |
| mysql.sys | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
4 rows in set (0.00 sec)
第三步,修改root密码
输入以下命令,其中123456是密码:
update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
mysql> update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
第四步,刷新
输入以下命令:
flush privileges;
然后重新启动服务器,就可以正常登录啦
sudo service mysql restart
边栏推荐
- 数据库系列之MySQL配置F5负载均衡
- 黑體輻射初探
- Detailed explanation of iptables firewall rules and firewalld firewall rules
- Online DDL implementation mechanism in InnoDB of database Series
- Summary of SQL basic syntax for C #
- 荣耀v8 真机调试时不显示 Logcat 日志的解决办法
- Introduction to kubernetes resource object and common commands
- A Preliminary Study of Blackbody radiation
- 开启创客教育造物学的领域
- 数据库系列之MySQL和TiDB中慢日志分析
猜你喜欢

多线程与高并发四:VarHandle与强软弱虚引用和ThreadLocal

Adder - Notes

ambari SSLError: Failed to connect. Please check openssl library versions.

小程序image组件不显示图片?

数据库系列之InnoDB中在线DDL实现机制

开关电源—Buck电路原理及其仿真

错排兼排列组合公式

Online DDL implementation mechanism in InnoDB of database Series

云应用、服务的“5层”架构

Websocket (simple experience version)
随机推荐
开关电源—Buck电路原理及其仿真
谈云原生,不得不谈的容器
Analysis of slow logs in MySQL and tidb of database Series
解析STEAM教育框架下未来教师研究能力
数据库系列之MySQL中的分页查询优化
数据库
如何给Eclips自动添加作者,时间等…
Summary of the use of composition API in the project
kubernetes资源对象介绍及常用命令
Execution plan in MySQL of database Series
指针链表
How to write anti shake throttling for small programs?
Cannot edit in read-only editor if it appears in vscode
Custom controls under WPF and adaption of controls in Grid
INFO:  HHH000397:  Using…
How the uni app automatically switches the requested address according to the environment
Automatic backup of MySQL database
门级建模—学习笔记
vscode中出现无法在只读编辑器中编辑
MySQL 数据库的自动备份操作