error 1044 (42000):access denied for user ''@'localhost' to database 'mysql'

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

重新安装mariaDB数据库时,出现安装权限问题,中止安装发现居然能够登陆mysql,但是登陆时可以不填密码,操作数据库时会报错:ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'。我是远程登录数据库的,网上找了一些方法,终于搞定了。
 
后来解决成功,发现是因为mariaDB数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的''@'localhost'可以看出来。解决方法如下:
 
在my.cnf的[mysqld]字段加入: 

[delphi] view plain copy

  1. skip-grant-tables  


重启mysql服务,这时的mariaDB不需要密码即可登录数据库

然后进入mariaDB

[sql] view plain copy

  1. mysql>use mysql;  

  2. mysql>delete from user where user='';   

  3. mysql>flush privileges;  


删除掉匿名用户,即可以root方式登陆数据库。

运行之后最后去掉my.ini中的skip-grant-tables,重启数据库(systemctl restart mariadb.service)即可。

版权声明:本文为博主原创文章,转载请注明来源。

本文转自   tianshuai369   51CTO博客,原文链接:http://blog.51cto.com/songqinglong/1967080

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
存储 容灾 安全
在阿里云RDS(Relational Database Service)迁移前准备目标区域选择
在阿里云RDS(Relational Database Service)迁移前准备目标区域选择
23 3
|
2月前
|
存储 关系型数据库 数据库
进行RDS(Relational Database Service)迁移时,资源需求分析
进行RDS(Relational Database Service)迁移时,资源需求分析
30 3
|
2月前
|
SQL 运维 关系型数据库
在阿里云RDS(Relational Database Service)进行跨区域迁移
在阿里云RDS(Relational Database Service)进行跨区域迁移
38 2
|
2月前
|
存储 运维 容灾
在规划阿里云RDS(Relational Database Service)跨区迁移
在规划阿里云RDS(Relational Database Service)跨区迁移
38 1
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.
|
1月前
|
Java 数据库连接 mybatis
解决Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: No constructor found
解决Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: No constructor found
85 1
|
2月前
|
存储 监控 关系型数据库
在规划和准备阿里云RDS(Relational Database Service)跨区域迁移
在规划和准备阿里云RDS(Relational Database Service)跨区域迁移
19 1
|
3月前
|
SQL 数据采集 关系型数据库
如何解决MySQL报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL?
如何解决MySQL报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL?
|
22天前
|
关系型数据库 MySQL 数据安全/隐私保护
MySQL连接ERROR 2059 (HY000): Authentication plugin ‘caching_sha2_password‘ cannot be loaded
MySQL连接ERROR 2059 (HY000): Authentication plugin ‘caching_sha2_password‘ cannot be loaded
26 0
|
1月前
|
缓存 关系型数据库 MySQL
MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES)无法打开的解决方法
MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES)无法打开的解决方法