windows下mysql提示access denied for user ''@'localhost' to database解决方案

用root帐号连上mysql,语句为“mysql -u root”即可,然后创建一个数据库,提示如下错误:
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mydb'

原因是因为mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的”@’localhost’可以看出来。

由于网上大多是linux下解决方案,但是在windows下输入命令却有不同,经过在网上查找试验,终于找到一个比较有效的方法,现整理如下:

1、cmd下cd到mysql的bin目录

输入mysqld --defaults-file="D:\Program Files\MySQL\MySQL Server 5.6\my-default.ini" --console --skip-grant-tables

看到下面这个结果就说明MySQL已经起来了:

2014-08-29 10:40:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use
2014-08-29 10:40:48 8108 [Note] Plugin 'FEDERATED' is disabled.
2014-08-29 10:40:48 8108 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-08-29 10:40:48 8108 [Note] InnoDB: The InnoDB memory heap is disabled
2014-08-29 10:40:48 8108 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2014-08-29 10:40:48 8108 [Note] InnoDB: Memory barrier is not used
2014-08-29 10:40:48 8108 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-08-29 10:40:48 8108 [Note] InnoDB: Not using CPU crc32 instructions
2014-08-29 10:40:48 8108 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-08-29 10:40:48 8108 [Note] InnoDB: Completed initialization of buffer pool
2014-08-29 10:40:48 8108 [Note] InnoDB: Highest supported file format is Barracuda.
2014-08-29 10:40:57 8108 [Note] InnoDB: 128 rollback segment(s) are active.
2014-08-29 10:40:57 8108 [Note] InnoDB: Waiting for purge to start
2014-08-29 10:40:57 8108 [Note] InnoDB: 5.6.20 started; log sequence number 1625997
2014-08-29 10:40:57 8108 [Note] Server hostname (bind-address): '*'; port: 3306
2014-08-29 10:40:57 8108 [Note] IPv6 is available.
2014-08-29 10:40:57 8108 [Note]   - '::' resolves to '::';
2014-08-29 10:40:57 8108 [Note] Server socket created on IP: '::'.
2014-08-29 10:40:58 8108 [Note] mysqld: ready for connections.
Version: '5.6.20'  socket: ''  port: 3306  MySQL Community Server (GPL)

2、再开一个dos窗口,cd到mysql bin目录下,输入mysql -u root mysql

出现下面这个结果说明已连接上mysql数据库,可以输入mysql命令了:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.20 MySQL Community Server (GPL)

mysql>

3、设置密码

mysql> update user set password=PASSWORD('password') where user='root';
Query OK, 2 rows affected (0.02 sec)
Rows matched: 3  Changed: 2  Warnings: 0

mysql> FLUSH PRIVILEGES; 
mysql> quit 

之后按正常方法连接mysql就可以了。如果不能连接,查看下mysql服务是否启动。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值