java - mariadb ERROR 1045 (28000)

 沙鹰之眼 发布于 2022-11-04 22:10

1、 运行环境: mariadb

2、 操作系统: centos7

3、 问题如下

之前数据库设置的是有密码登陆,现在出现用密码不能登录,而无密码可以登录。登录后不能创建数据库。求原因

一下我的操作:

[root@localhost ~]# mysql -uroot -p123456
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost ~]# mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]>

MariaDB [(none)]> create database test1;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'test1'
MariaDB [(none)]>

我试了网上的方法,如下:
1.关闭mysql
# systemctl stop maraidb.sevice
2.屏蔽权限
# mysqld_safe --skip-grant-table
屏幕出现: Starting demo from .....
3.新开起一个终端输入
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
mysql> \q

仍然不行,现在只能对数据库读,其他的操作都不能进行,求原因???

谢谢!!!

1 个回答
  • 题目中提到了两个错误:
    ERROR 1045 (28000)这个是账号密码错误,题主已经解决了。
    ERROR 1044 (42000)这个是权限不足的引起的。

    作者参考的解决办法或许来自这下面的文章之一:
    1. http://www.cnblogs.com/Anker/p/3551610.html
    2. http://blog.csdn.net/tys1986blueboy/article/details/7056835

    我想说我的看法:

    mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
    mysql> FLUSH PRIVILEGES;
    

    第一行是修改密码,第二行是刷新保存(权限)。

    从排查问题的角度来看这样解决问题还是不那么负责任的。
    建议用新的账号密码登陆后,查看用户的权限,参考http://yanue.net/post-96.html

    mysql> show grants for root@localhost;
    

    一般来说root@localhost用户的权限是最大的。
    如果确定这一点,那么就可以做其他授权。

    grant all privileges on *.* to 'test'@'127.0.0.1' identified by 'passwd';
    

    如果root@localhost权限也是有问题的,
    参考:http://stackoverflow.com/questions/10130296/mysql5-as-root-cant-create...
    换一种启动方式,加入--skip-grant-tables参数,然后登陆后修正权限问题。

    2022-11-08 14:30 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有