linux+登录+mysql+1045_Linux 下,mysql数据库报无法登陆错误:ERROR 1045 (28000): Access denied for user ‘admin’@'l...

注--该方法也可以用于当忘记数据库密码时,找回数据库密码用

如下是我执行过程,完全执行后,可以顺利登录数据库:linux下的执行脚本:

login as: root

Access denied

root@×××××××'s password:

Last login: Tue Feb 21 03:56:49 2012 from 218.17.162.225

[root@INOTRADE ~]# ps -A

PID TTY TIME CMD

1 ? 00:00:01 init

1117 ? 00:00:00 udevd

1394 ? 00:00:00 syslogd

1405 ? 00:00:00 sshd

1414 ? 00:00:00 xinetd

1427 ? 00:00:00 couriertcpd

1429 ? 00:00:00 courierlogger

1437 ? 00:00:00 couriertcpd

1439 ? 00:00:00 courierlogger

1445 ? 00:00:00 couriertcpd

1447 ? 00:00:00 courierlogger

1454 ? 00:00:00 couriertcpd

1456 ? 00:00:00 courierlogger

1466 ? 00:00:00 qmail-send

1468 ? 00:00:00 splogger

1469 ? 00:00:00 qmail-lspawn

1470 ? 00:00:00 qmail-rspawn

1471 ? 00:00:00 qmail-clean

1486 ? 00:00:00 httpd

1528 ? 00:00:00 named

1573 ? 00:00:00 mysqld_safe

1623 ? 00:00:00 mysqld

1629 ? 00:00:00 httpd

1655 ? 00:00:00 httpsd

1659 ? 00:00:00 httpsd

1674 ? 00:00:00 crond

1682 ? 00:00:00 saslauthd

1683 ? 00:00:00 saslauthd

1689 ? 00:00:00 sshd

1691 pts/0 00:00:00 bash

1718 pts/0 00:00:00 ps

// 无法登陆,密码正确的,不知道为什么,原来数据库表的访问权限也已经设置了的

[root@INOTRADE ~]# mysql -uroot -p

Enter password:

[root@INOTRADE ~]# ERROR 1045 (28000): Access denied for user ‘admin’@'localhost’ (using password: YES)

[root@INOTRADE ~]# mysql -uroot -p****** -hlocalhost

[root@INOTRADE ~]# ERROR 1045 (28000): Access denied for user ‘admin’@'localhost’ (using password: YES)

// 执行脚本,更新mysql数据库的数据,如用户名密码

[root@INOTRADE ~]# sudo /etc/init.d/mysqld stop

Stopping MySQL: [ OK ]

[root@INOTRADE ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

[1] 1759

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

[root@INOTRADE ~]# Starting mysqld daemon with databases from /var/lib/mysql

-- 这步可能不会自动执行,等待十几秒后就可以直接回车返回到命令行模式下,然后登录到mysql服务器

[root@INOTRADE ~]#

[root@INOTRADE ~]# mysql -u root mysql

Reading table information for completion of table and column names

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

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select host, user from user;

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

| host | user |

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

| % | admin |

| localhost | admin |

| localhost | horde |

| localhost | pma_OBBVuV2L3mjn |

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

4 rows in set (0.00 sec)

-- 因为我数据库中没有root,换为admin了

mysql> UPDATE user SET Password=PASSWORD('******') where USER='admin';

Query OK, 2 rows affected (0.02 sec)

Rows matched: 2 Changed: 2 Warnings: 0

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.02 sec)

mysql> quit;

Bye

[root@INOTRADE ~]# /etc/init.d/mysqld restart

STOPPING server from pid file /var/run/mysqld/mysqld.pid

120221 05:08:02 mysqld ended

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

[1]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking

// 至此, 重启后就可以正常登录了

[root@INOTRADE ~]# mysql -uadmin -p******

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;

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

| Database |

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

| information_schema |

| ******* |

| horde |

| mysql |

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

7 rows in set (0.01 sec)

mysql> use ********;

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> show tables;

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

| Tables_in_CQT_AMS |

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

| T_ALM_APPLICATION |

| ***************** |

| T_SYS_ROLE |

| T_SYS_USER_INFO |

| T_SYS_USER_ROLE |

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

22 rows in set (0.00 sec)

mysql> quit

Bye

[root@INOTRADE ~]#

以上代码,参考了网上的相关资料

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2012-02-21 12:28

浏览 14478

分类:数据库

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值