mysql root 不能登录_mysql root 用户不能登录的问题

#apt-get install mysql-server-5.0

#mysql -u root

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

发现不能登录。或者登录后没有权限操作。原因是因为在安装时没有给root设置密码而默认其为空的。

可以尝试以下的方法:

方法1 执行 root@hettvm2:~# mysqladmin -u root password 123456

设置了root的密码。

方法2

# /etc/init.d/mysql stop

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';

mysql> FLUSH PRIVILEGES;

mysql> quit

# /etc/init.d/mysql restart

# mysql -uroot -p

Enter password:

mysql>

方法3

MySQL安装之后,root的密码是空的。为了提高安全性有必要给root加上密码。

mysql –u root –p

password:

mysql>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Password');

下次登陆时,就必须输入密码了。

给其他用户付权限则使用下面的语句:

grant all privileges on *.* to $usrname@"localhost" identified by "$password"

注:$是变量。表示用户名和密码

localhost是本地。如果是远程登录的话应该使用 “%”。

在mysql里有一张记录用户的表

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select host,user,password from user;

+-----------+------------------+-------------------------------------------+

| host | user | password |

+-----------+------------------+-------------------------------------------+

| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| hettvm2 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| localhost | | |

| hettvm2 | | |

| localhost | debian-sys-maint | *6E20E21227143F48BD9E44BC7352C8855AE14A52 |

| % | starent | *BE6D39BA79EE21926B287198D86AC1573DA755EC |

| % | hettvm2 | *BE6D39BA79EE21926B287198D86AC1573DA755EC |

| localhost | hettvm2 | *BE6D39BA79EE21926B287198D86AC1573DA755EC |

+-----------+------------------+-------------------------------------------+

9 rows in set (0.00 sec)

mysql>

可以通过这个表查询用户。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值