当前位置:网站首页>【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
边栏推荐
- 光的粒子说(光电效应/康普顿效应)
- 数字电路学习笔记(一)
- 黑体辐射初探
- ambari SSLError: Failed to connect. Please check openssl library versions.
- django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
- 物体上下漂浮工具
- 电学基础知识整理(二)
- Circular sliding auto adsorption UI tool that monkeys can use
- Change of monitoring documents and folders of "operation and maintenance department"
- English notes - cause and effect
猜你喜欢
随机推荐
密码加密md5和加盐处理
开口式霍尔电流传感器如何助力直流配电改造?
Resource management, high availability and automation (medium)
ambari SSLError: Failed to connect. Please check openssl library versions.
Arrangement of basic electrical knowledge (I)
MySQL error
双亲委派机制的理解学习
TypeScript 联合类型
错排兼排列组合公式
INFO:  HHH000397:  Using…
How to write anti shake throttling for small programs?
失联修复:让“躲猫猫”无处可藏
一文告诉你什么是 Kubernetes
iptables防火墙规则和firewalld防火墙规则详解
Self use tool unity video player that monkeys can use
Li Kou daily question - day 29 -523 Count odd numbers in interval range
What is the difference between slice and array in go question bank 12?
物体上下漂浮工具
Pycharm不同项目之间共用第三方模块
英语小记 - 表因果








