ERROR 1044 (42000) ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'
ERROR: Access denied for user 'root'@'localhost' (using password: NO)
发现:
mysql -u root@localhost -p 成功
mysql -u root -p 失败
mysql> SELECT user, host FROM mysql.user;
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'
mysql> SELECT USER(), CURRENT_USER();
+--------------------------+----------------+
| USER() | CURRENT_USER() |
+--------------------------+----------------+
| root@localhost@localhost | @localhost |
+--------------------------+----------------+
1 row in set (0.01 sec)
原因: root 设置了密码,需要把root的密码清掉。
以下可以解决问题(方案一):
1) service mysqld stop
2) mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
3) mysql -u root
4) Setup new MySQL root user password
use mysql;
select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *CF1E6A25C954B638A451D6|
| root | centos64 | |
| root | 127.0.0.1 | |
| | localhost | |
| | centos64 | |
+------+-----------+-------------------------------------------+
update mysql.user set password=PASSWORD("***********") where User='root';
select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *CF1E6A25C954B638A451D6 |
| root | centos64 | *CF1E6A25C954B638A451D6|
| root | 127.0.0.1 | *CF1E6A25C954B638A451D6|
| | localhost | |
| | centos64 | |
+------+-----------+-------------------------------------------+
flush privileges;
quit
5) Stop MySQL Server: service mysqld stop
6) Start MySQL server and test it:
service mysqld start
mysql -u root -p
SELECT USER(),CURRENT_USER();
+----------------+----------------+
| USER() | CURRENT_USER() |
+----------------+----------------+
| root@localhost | root@localhost |
+----------------+----------------+
1 row in set (0.00 sec)
以下可以解决问题(方案二):
先用方案一登录mysql,再把root的密码设置为空
use mysql;
update user set password=PASSWORD("****************") where User='root';
flush privileges;
quit
=========================
在授权的时候报错:
ERROR 1044 (42000): Access denied for user 'root'@'%' to database 'mdm'
首先这里是用root用户操作,所以对这个数据库的权限绝对是最高级的,但是如果是非root用户操作,就可能是权限的问题,需要root用户授权。
出现上面的报错,很可能,其实应该可以说基本上都是因为my.cnf 文件里面有skip-name-resolve参数,这个参数导致这不能解析hostname或其它方式的登录, 所以登录任何用户,匹配的时候不走root@'localhost',或者127.0.0.1或者::1 ,而是 一个劲的走root@'%'.
再来查看一下每种方式下的root用户的具体权限:
mysql> select * from user\\G;
我这里root有三种解析登录方式分别是:Host: bidevedw\_db、Host: ::1、Host: %
一般情况还有Host:127.0.0.1、Host:localhost我的里面把哪两种删了。
请注意 !
注意上面每条记录的的红色字体部分Grant_priv: Y
这个表示,以这种方式解析登录的root用户,是否有grant权限,Y则表示有授权限给其他用户的权限,N表示没有。
这里恰好,就是我们要找的原因,因为我的/my.cnf文件里面有skip-name-resolve参数,所以root都是解析到@'%'方式登录,于是就没有grant_priv权限。
解决方法:
1、在不重启MySQL服务的情况下,只需要在登录的时候加上-h参数。
例如:(a). /usr/local/mysql/bin/mysql -uroot -p123456 -h::1
(b)./usr/local/mysql/bin/mysql -uroot -p123456 -h127.0.0.1
(c)./usr/local/mysql/bin/mysql -uroot -p123456 -hlocalhost
2、需要重启MySQL。把skip-name-resolve参数去掉 ---- 还没验证。不过我记得,如果去掉了,日志里面会有大量的警告信息。我是因为那些警告信息,才添加的这个参数。
=========================================
HTTP Status 500 - javax.servlet.ServletException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
grant all privileges on aldb.* to root@localhost;
grant select on aldb.* to nobody@localhost;
grant all privileges on aldb.* to root@112.112.112.112;
grant select on aldb.* to nobody@112.112.112.112;
grant all privileges on aldb.* to root@res.res.res.res;
grant select on aldb.* to nobody@res.res.res.res;
use mysql
update user set password=password('xxxxxxxxxx') where user='root';
flush privileges;
====================================================
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
-----------------------------
/etc/init.d/mysqld status
/etc/init.d/mysqld stop
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
需要使用Enter中断会话
mysql -u root -p -hlocalhost
mysql> use mysql;
select Host, User, Password from user where user='root' and host='root' or host='localhost';
+-----------+--------+----------+
| Host | User | Password |
+-----------+--------+----------+
| localhost | | |
| localhost | aimin | |
| localhost | nobody | |
| localhost | root | |
+-----------+--------+----------+
4 rows in set (0.00 sec)
update user set password=PASSWORD('XXXXXXXXXXXXXX') where user='root' and host='root' or host='localhost';
flush privileges;
quit
/etc/init.d/mysqld restart
mysql -u root -p -hlocalhost
----------------------------------------------
# service mysqld stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root -p -hlocalhost
mysql> UPDATE user SET Password=PASSWORD('xxxxxxxxxxxxxxxxxxxxx') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
# service mysqld start
restart CentOS.
-------------------------------------
Access denied for user 'root'@'localhost' (using password: YES)
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'
SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;
UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
FLUSH PRIVILEGES;
GRANT ALL ON *.* TO 'root'@'localhost';
GRANT ALL ON *.* TO 'root'@'127.0.0.1';
GRANT ALL ON *.* TO 'root'@'xyz.xyz.com.cn';
GRANT ALL ON *.* TO 'root'@'123.123.123.123';
FLUSH PRIVILEGES;
quit
REF:
http://www.cnblogs.com/kerrycode/p/3861719.html
https://help.ubuntu.com/community/MysqlPasswordReset
http://blog.itpub.net/27099995/viewspace-1362951/
ERROR 1044 (42000) ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'的更多相关文章
- [已解决]#1142 - SELECT command denied to user ''@'localhost' for table 'pma_table_uiprefs'
症状:在phpmyadmin那边打不开表,提示 #1142 - SELECT command denied to user ''@'localhost' for table 'pma_table_ui ...
- [phpmyadmin] phpmyadmin select command denied to user
phpmyadmin 在查看一个数据库中Table的数据的时候,会提示 select command denied to user 在Ubuntu下,我是使用重装Phpmyadmin的方式解决的 卸载 ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user’
Linux环境 Mysql+Hibernate command denied to user 错误 错误信息 如下: com.mysql.jdbc.exceptions.jdbc4.MySQLSynt ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'xxxx'@''
这两天项目一直在报这个错误消息: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to ...
- MySQL:select command denied to user for table 'proc'案例
使用EMS MySQL Manager Pro(3.4.0.1)连接MySQL 5.6.20时,报错:"SELECT command denied to user xxx@xxx.xxx.x ...
- SELECT command denied to user ''@'%' for column 'xxx_id' in table 'users_xxx' 权限问题
问题的原因是:最主要是权限的问题. 大概说下 ,我导数据库时提示错误:SELECT command denied to user ''@'%' for column 'xxx_id' in table ...
- SELECT command denied to user 'username'@'ip' for table 'user'错误处理
错误信息 使用RDS for MySQL,程序执行查询SQL时报错如下: SELECT command denied to user 'username'@'ip' for table 'user' ...
- 1142 - show view command denied to user
原因是没有给test用户授予"show_view_priv"权限 mysql> SELECT * FROM mysql.user WHERE User = 'test' an ...
- 1142 CREATE VIEW command denied to user 'blog'@'XXX.XXX.XXX.XXX' for table 'Articles'
创建视图时,报如上的1142错误,是数据库权限设置的问题. 进入mysql的root用户,赋予所有权限即可: mysql>grant all privileges on blogDB.* to ...
随机推荐
- owner window 和 parent window 有什么区别?
1.Pop-up窗口: 一个弹出窗口是必须具有WS_POPUP属性的窗口,弹出窗口只能是一个Top-Level窗口,不能是子窗口,弹出窗口多用于对话框和消 ...
- mysql笔记01 MySQL架构与历史、Schema与数据类型优化
MySQL架构与历史 1. MySQL架构推荐参考:http://www.cnblogs.com/baochuan/archive/2012/03/15/2397536.html 2. MySQL会解 ...
- CasperJS基于PhantomJS抓取页面
CasperJS基于PhantomJS抓取页面 Casperjs是基于Phantomjs的,而Phantom JS是一个服务器端的 JavaScript API 的 WebKit. CasperJS是 ...
- linux设备树笔记__dts基本概念及语法【转】
转自:http://www.360doc.com/content/15/1113/11/15700426_512794532.shtml 设备树手册(Device Tree Usage)原文地址:ht ...
- WinCE Show App Icon
找个图片,例如背景透明的jpg或png,上http://www.pic2icon.com/smartphone_wince_icon_generator.php这个网站转换下. 在项目属性中,设为图标 ...
- maven打包异常:软件包com.sun.org.apache.xml.internal.security.utils.Base64 不存在
maven打包异常:软件包com.sun.org.apache.xml.internal.security.utils.Base64 不存在 将jre/lib/rt.jar添加到maven的compi ...
- 安装使用RESTful 框架SLIM方法
相关框架: http://www.golaravel.com 是一个PHP框架,内置名为LUMEN的RESTful API框架,有中文文档, http://lumen.golaravel.com/do ...
- jquery+thinkphp实现跨域抓取数据的方法
jquery的$.post发送数据到服务器后台,在由后台的PHP代码执行远程抓取,存到数据库ajax返回数据到前台,前台用JS接受数据并显示. //远程抓取获取数据$("#update_ac ...
- CodeIgniter配置之config
配置说明 $config['language']:指定项目语言包.需要注意的时Codeigniter自带的类库错误提示语言包位于/system/language/english/目录下,当这里配置非e ...
- ab测试大并发错误
转载自http://xmarker.blog.163.com/blog/static/226484057201462263815783 apache 自带的ab工具测试,当并发量达到1000多的时候报 ...