mysql root 用户不能登录的问题

上一篇 / 下一篇  2008-10-16 14:37:44

#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: <输入新设的密码newpassword>

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> 

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





TAG:

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-13  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 5509
  • 日志数: 10
  • 建立时间: 2008-07-04
  • 更新时间: 2009-01-09

RSS订阅

Open Toolbar