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
仍然不行,现在只能对数据库读,其他的操作都不能进行,求原因???
谢谢!!!
题目中提到了两个错误:
ERROR 1045 (28000)
这个是账号密码错误,题主已经解决了。ERROR 1044 (42000)
这个是权限不足的引起的。作者参考的解决办法或许来自这下面的文章之一:
1. http://www.cnblogs.com/Anker/p/3551610.html
2. http://blog.csdn.net/tys1986blueboy/article/details/7056835
我想说我的看法:
第一行是修改密码,第二行是刷新保存(权限)。
从排查问题的角度来看这样解决问题还是不那么负责任的。
建议用新的账号密码登陆后,查看用户的权限,参考http://yanue.net/post-96.html
一般来说
root@localhost
用户的权限是最大的。如果确定这一点,那么就可以做其他授权。
如果
root@localhost
权限也是有问题的,参考:http://stackoverflow.com/questions/10130296/mysql5-as-root-cant-create...
换一种启动方式,加入
--skip-grant-tables
参数,然后登陆后修正权限问题。