zoukankan      html  css  js  c++  java
  • mysql ERROR 1044 (42000): Access denied for user ''@'localhost' to database

    新安装的mysql密码是空的。

    ./mysql -u root -p
    use mysql
    SELECT `Host`,`User` FROM user;
    UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
    FLUSH PRIVILEGES;

    GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'%' IDENTIFIED BY 'test' WITH GRANT OPTION;

    方法一:
    1.关闭mysql
       # service mysqld stop
    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

     
    方法
    mysql> use mysql
    ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'
    mysql> exit
    Bye
    [root@testtest ~]# service mysqld stop 
    Stopping mysqld:                      [ OK ]
    [root@testtest ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
     
    [root@testtest ~]# mysql -u root -p -hlocalhost
    Enter password: 
     
    mysql> use mysql
     
    mysql> SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;
     
    mysql> UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
     
    mysql> FLUSH PRIVILEGES;
     
    mysql> GRANT ALL ON *.* TO 'root'@'localhost';
     
    mysql> GRANT ALL ON *.* TO 'root'@'cn.cn.cn.cn';
     
    mysql> GRANT ALL ON *.* TO 'root'@'245.245.245.245';
     
    mysql> GRANT ALL ON *.* TO 'root'@'127.0.0.1';
     
    mysql> FLUSH PRIVILEGES;
     
     
    mysql> quit
    Bye
    [root@testtest ~]# service mysqld start 

    方法三:

    在my.ini的[mysqld]字段加入: 
    skip-grant-tables
    重启mysql服务,这时的mysql不需要密码即可登录数据库
    然后进入mysql 
    mysql>use mysql;
    mysql>update user set password=password('新密码') WHERE User='root';
    mysql>flush privileges;
    运行之后最后去掉my.ini中的skip-grant-tables,重启mysqld即可。
     
     
     
     
    mysql> use mysql
    ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'
    mysql> exit
    Bye
    [root@testtest ~]# service mysqld stop
    Stopping mysqld:                      [ OK ]
    [root@testtest ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
     
    [root@testtest ~]# mysql -u root -p -hlocalhost
    Enter password:
     
    mysql> use mysql
     
    mysql> SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;
     
    mysql> UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
     
    mysql> FLUSH PRIVILEGES;
     
    mysql> GRANT ALL ON *.* TO 'root'@'localhost';
     
    mysql> GRANT ALL ON *.* TO 'root'@'cn.cn.cn.cn';
     
    mysql> GRANT ALL ON *.* TO 'root'@'245.245.245.245';
     
    mysql> GRANT ALL ON *.* TO 'root'@'127.0.0.1';
     
    mysql> FLUSH PRIVILEGES;
     
     
    mysql> quit
    Bye
    [root@testtest ~]# service mysqld start
  • 相关阅读:
    转载--重写、覆盖、重载、多态几个概念的区别分析
    笔试题--奇虎360-2013
    转载---数据挖掘十大经典算法
    Nginx的启动、停止与重启
    程序员的十种级别,看看你属于哪一种?
    C标签的用法
    eclipse修改代码后都需要clean的解决办法
    创建一个jFinal项目
    java redirect用法
    java获取访问者真实的IP地址
  • 原文地址:https://www.cnblogs.com/shihaiming/p/6112388.html
Copyright © 2011-2022 走看看