新手一枚。
root的密码为空。匿名用户的密码为空。
用 mysql -u root或者mysql -u root -p  登录就变成匿名用户了。
无法查看到部分数据库。
创建数据库也出错。Access denied for user ''@'localhost' to database XXX。
网上很多的解决方法是:方法一:
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方法二:
1.关闭mysql
   # service mysqld stop
2.屏蔽权限
   # mysqld_safe --skip-grant-table
   屏幕出现: Starting demo from .....
3.新开起一个终端输入
   # mysql -u root mysql
   mysql> delete from user where USER='';
   mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
   mysql> \q
可我是在windows下啊。
另外。有想过先改root的密码,但都因为进不了mysql而无法修改。
求解决方法。

解决方案 »

  1.   

    改root密码
    grant all on *.* to root@'%' identified by 'yourpassword';
      

  2.   

    参考下贴三楼
    http://topic.csdn.net/u/20090515/21/2b3c9a12-d8a5-4bb1-9895-6069cef5aef8.html
      

  3.   


    昨天认真研习了您的方法。出现下面的问题,还望帮忙解决:C:\xampp\mysql\bin>mysqld --default-file="C:\xampp\mysql\bin\my.ini" --console -
    -skip-grant-tables
    120608  0:47:10 [Note] Plugin 'FEDERATED' is disabled.
    InnoDB: The InnoDB memory heap is disabled
    InnoDB: Mutexes and rw_locks use Windows interlocked functions
    InnoDB: Compressed tables use zlib 1.2.3
    120608  0:47:10  InnoDB: Initializing buffer pool, size = 128.0M
    120608  0:47:10  InnoDB: Completed initialization of buffer pool
    120608  0:47:10  InnoDB: Operating system error number 32 in a file operation.
    InnoDB: The error means that another program is using InnoDB's files.
    InnoDB: This might be a backup or antivirus software or another instance
    InnoDB: of MySQL. Please close it to get rid of this error.关掉,再打开dos。
    C:\xampp\mysql\bin>mysql -u root
    此时再登陆进去mysql,仍然为匿名用户。
    源语句中为“defaults”但这样会导致无法进行输入且光标不移动。只能关闭dos。
    然后看了  magnet2008(13楼)的意见,先讲mysql关掉,使用语句net stop mysql,再输入您的语句命令,
    结果如下:  C:\xampp\mysql\bin>net stop mysql
    mysql 服务正在停止.
    mysql 服务已成功停止。
    C:\xampp\mysql\bin>mysqld --default-file="C:\xampp\mysql\bin\my.ini" --console -
    -skip-grant-tables
    120608  0:49:13 [Note] Plugin 'FEDERATED' is disabled.
    InnoDB: The InnoDB memory heap is disabled
    InnoDB: Mutexes and rw_locks use Windows interlocked functions
    InnoDB: Compressed tables use zlib 1.2.3
    120608  0:49:13  InnoDB: Initializing buffer pool, size = 128.0M
    120608  0:49:13  InnoDB: Completed initialization of buffer pool
    120608  0:49:13  InnoDB: highest supported file format is Barracuda.
    120608  0:49:13  InnoDB: 1.1.4 started; log sequence number 1630496
    120608  0:49:13 [ERROR] mysqld: unknown variable 'default-file=C:\xampp\mysql\bi
    n\my.ini'
    120608  0:49:13 [ERROR] Aborting120608  0:49:13  InnoDB: Starting shutdown...
    120608  0:49:15  InnoDB: Shutdown completed; log sequence number 1630496
    120608  0:49:15 [Note] mysqld: Shutdown complete接下来进行C:\xampp\mysql\bin>mysql -u root,也仍然为匿名用户。
    后来不知道又参考了某些其他网页上的语句,进行非常多次的尝试(包括互相叠加组合什么的)
    终于有一次登陆进去为:
    mysql> select current_user()\g
    +----------------+
    | current_user() |
    +----------------+
    | @              |
    +----------------+
    应该是admin用户之类的。
    可以进入mysql表。
    之后就用update语句,可是万分不幸的是,我在用您引用的帖子中的方法一时:
    将原本的语句
    mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’;  
    mysql> FLUSH PRIVILEGES;  
    mysql> quit  
    里的UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; 
    错写为:UPDATE user SET Password=’newpassword’ where USER=’root’; 
    具体如下:
    mysql> use mysql
    Database changed
    mysql> update user set password='newpassword' where user='root';
    Query OK, 2 rows affected (0.08 sec)
    Rows matched: 2  Changed: 2  Warnings: 0mysql> flush privileges;
    Query OK, 0 rows affected (0.05 sec)mysql> \q
    Bye
    这样出错的语句,可能使得密码更改有些问题。
    因为
    退出后再登进去就不行了
    C:\xampp\mysql\bin>mysql -uroot -p
    Enter password: *********
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y
    ES)
    !!!!!!!!我保证密码没出错。
    现在的关键是,我不管再怎么输入命令都没法使之为
    mysql> select current_user()\g
    +----------------+
    | current_user() |
    +----------------+
    | @              |
    +----------------+
    这个身份登陆。不管怎么做都是匿名登陆PS:如花似玉的姑娘读计算机简直就是自我摧残以及自我毁灭。
      

  4.   

    -u root
    应该 -uroot
    u和root之间没有空格
    Linux的单个 - 的参数都是直接跟参数值,无需空格