开发者社区> 问答> 正文

mariadb ERROR 1045 (28000)

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 |

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
仍然不行,现在只能对数据库读,其他的操作都不能进行,求原因?

展开
收起
蛮大人123 2016-02-27 15:25:06 3864 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    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参数,然后登陆后修正权限问题。
    参考:http://www.cnblogs.com/Anker/p/3551610.html

    2019-07-17 18:48:55
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
从花农到MySQL大 立即下载
从华农到MySQL大神 立即下载
MySQL Replication: Latest Developments 立即下载