首页 > 其他分享 >ERROR 1044 (42000) ERROR 1142 (42000): SELECT command denied to user ''@'localhost�

ERROR 1044 (42000) ERROR 1142 (42000): SELECT command denied to user ''@'localhost�

时间:2023-11-06 15:35:31浏览次数:58  
标签:grant ERROR 42000 user mysql password root localhost

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 [email protected];
  grant select on aldb.* to [email protected];
  grant all privileges on aldb.* to [email protected];
  grant select on aldb.* to [email protected];

 

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

===========================================================================

步骤:

创建数据库

创建用户,设置密码

给用户授权

用户和密码、主机都设置了,localhost和%主机都可以使用

设置了防火墙,开放端口; 或者禁用防火墙;

结果:

主机上可以访问;远程无法访问;

root不能远程访问;其他用户?

ERROR 1044 (42000) ERROR 1142 (42000): SELECT command denied to user

 

 

===========================================================================

REF:


https://help.ubuntu.com/community/MysqlPasswordReset

http://blog.itpub.net/27099995/viewspace-1362951/



标签:grant,ERROR,42000,user,mysql,password,root,localhost
From: https://blog.51cto.com/emanlee/8212563

相关文章

  • 502 Proxy Error The proxy server received an invalid response from an upstream s
    ProxyErrorTheproxyserverreceivedaninvalidresponsefromanupstreamserver.TheproxyservercouldnothandletherequestGET /wpsp/.Reason:ErrorreadingfromremoteserverApache/2.2.15(CentOS)Serveratwww.xaut.edu.cnPort80 解决方法:重启Apache,再......
  • Continue SQL query even on errors
    trymysql--force<sample_data.sqlMysqlhelpsectionsays -f,--force        Continueevenifwegetansqlerror.----------------------YoucouldalsouseINSERTIGNOREINSERTIGNOREINTOmytable (primaryKey,field1,field2)VALUES ('1',1,2......
  • ImportError: No module named argparse
    如果有root权限,可以运行:easy_installargparse 如果没有root权限,Asasimplesolutioncopyargparse.pyfromhttps://code.google.com/p/argparse/source/browse/argparse.pytoyourprojectfolder. REF:https://pypi.python.org/pypi/argparsehttps://code.google.com/p/arg......
  • mac os 编译webrtc 报错screen_capturer_mac.mm:500:5: error: 'CGDisplayStreamStop'
    ../../modules/desktop_capture/mac/screen_capturer_mac.mm:462:11:error:'CGDisplayStreamUpdateGetRects'isonlyavailableonmacOS13.0ornewer[-Werror,-Wunguarded-availability-new]462|CGDisplayStreamUpdateGetRects(updateRef,kC......
  • Java jar: A JNI error has occurred, please check your installation and try again
    java-verion和javac-version版本不一致 E:\temp\eclipseWorkSpace>java-jarTASTS.jarExceptioninthread"main"java.lang.NoClassDefFoundError:org/eclipse/swt/widgets/DecorationsCausedby:java.lang.ClassNotFoundException:org.eclipse.swt.widge......
  • Error: error:0308010C:digital envelope routines::unsupported
    "start":"SETNODE_OPTIONS=--openssl-legacy-provider&&cross-envUMI_ENV=devumidev","start:dev":"SETNODE_OPTIONS=--openssl-legacy-provider&&cross-envREACT_APP_ENV=devMOCK=noneUMI_ENV=devu......
  • ./rmblastn: error while loading shared libraries: libzstd.so.1: cannot open shar
     001、问题, ./rmblastn命令报错如下:./rmblastn:errorwhileloadingsharedlibraries:libzstd.so.1:cannotopensharedobjectfile:Nosuchfileordirectory 002、解决方法  003、测试  参考:01、https://www.modb.pro/db/429704 ......
  • Git error
    errorerror:failedtopushsomerefsto'remote_repository_address'问题/原因如果不确定本地版本是否是最新,最好先gitpullGit仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。远程仓库和本地仓库存在差异。一般都是因为你在码云创建的仓库有ReadMe文件......
  • 遇到的问题 vscode 连接远程主机报错 `Resolver error: Error: Got bad result from i
    解决方案我发现我的cmd.exe崩溃了(它会弹出并立即关闭)我将注册表值Autorun 从更改HKEY_CURRENT_USER\Software\Microsoft\CommandProcessor为ifexists空白(如此链接所示)。我的cmd.exe工作正常,远程SSH再次工作再次链接上远程主机......
  • Linux系统bash文件运行后出现error: unrecognized arguments中command not found的解
    跑了一个代码,如下图所示,我在配置完环境后运行了bash文件,结果是出现了commandnotfound,稍微找了一下解决方案,最后是在github上一个的仓库问题找到了思路,链接如下:为什么运行bashtrain.sh时一直说我的参数有错?·Issue#450·THUDM/ChatGLM-6B(github.com) 在我的文件是在......