Linux 下,mysql数据库报无法登陆错误:ERROR 1045 (28000): Access denied for use

今天在别人的服务器上登录mysql发现无法登陆(Mysql别人实现安装好的) 
密码和用户名都是正确的,但登录后报如下错误: 
ERROR 1045 (28000): Access denied for user ‘admin’@'localhost’ (using password: YES) 

尝试了加入-h和-port也无法登陆,最后只能重新修改了。注--该方法也可以用于当忘记数据库密码时,找回数据库密码用 

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

Java代码  收藏代码
    1. login as: root  
    2. Access denied  
    3. root@×××××××'s password:  
    4. Last login: Tue Feb 21 03:56:49 2012 from 218.17.162.225  
    5. [root@INOTRADE ~]# ps -A  
    6.   PID TTY          TIME CMD  
    7.     1 ?        00:00:01 init  
    8.  1117 ?        00:00:00 udevd  
    9.  1394 ?        00:00:00 syslogd  
    10.  1405 ?        00:00:00 sshd  
    11.  1414 ?        00:00:00 xinetd  
    12.  1427 ?        00:00:00 couriertcpd  
    13.  1429 ?        00:00:00 courierlogger  
    14.  1437 ?        00:00:00 couriertcpd  
    15.  1439 ?        00:00:00 courierlogger  
    16.  1445 ?        00:00:00 couriertcpd  
    17.  1447 ?        00:00:00 courierlogger  
    18.  1454 ?        00:00:00 couriertcpd  
    19.  1456 ?        00:00:00 courierlogger  
    20.  1466 ?        00:00:00 qmail-send  
    21.  1468 ?        00:00:00 splogger  
    22.  1469 ?        00:00:00 qmail-lspawn  
    23.  1470 ?        00:00:00 qmail-rspawn  
    24.  1471 ?        00:00:00 qmail-clean  
    25.  1486 ?        00:00:00 httpd  
    26.  1528 ?        00:00:00 named  
    27.  1573 ?        00:00:00 mysqld_safe  
    28.  1623 ?        00:00:00 mysqld  
    29.  1629 ?        00:00:00 httpd  
    30.  1655 ?        00:00:00 httpsd  
    31.  1659 ?        00:00:00 httpsd  
    32.  1674 ?        00:00:00 crond  
    33.  1682 ?        00:00:00 saslauthd  
    34.  1683 ?        00:00:00 saslauthd  
    35.  1689 ?        00:00:00 sshd  
    36.  1691 pts/0    00:00:00 bash  
    37.  1718 pts/0    00:00:00 ps  
    38.   
    39. // 无法登陆,密码正确的,不知道为什么,原来数据库表的访问权限也已经设置了的  
    40. [root@INOTRADE ~]# mysql -uroot -p  
    41. Enter password:  
    42. [root@INOTRADE ~]# ERROR 1045 (28000): Access denied for user ‘admin’@'localhost’ (using password: YES)  
    43.   
    44.   
    45. [root@INOTRADE ~]# mysql -uroot -p****** -hlocalhost  
    46. [root@INOTRADE ~]# ERROR 1045 (28000): Access denied for user ‘admin’@'localhost’ (using password: YES)  
    47.   
    48.   
    49. // 执行脚本,更新mysql数据库的数据,如用户名密码  
    50. [root@INOTRADE ~]# sudo /etc/init.d/mysqld stop  
    51. Stopping MySQL:                                            [  OK  ]  
    52. [root@INOTRADE ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  
    53. [1] 1759  
    54. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)  
    55. [root@INOTRADE ~]# Starting mysqld daemon with databases from /var/lib/mysql  
    56.   
    57. -- 这步可能不会自动执行,等待十几秒后就可以直接回车返回到命令行模式下,然后登录到mysql服务器  
    58.   
    59. [root@INOTRADE ~]#  
    60. [root@INOTRADE ~]# mysql -u root mysql  
    61. Reading table information for completion of table and column names  
    62. You can turn off this feature to get a quicker startup with -A  
    63.   
    64. Welcome to the MySQL monitor.  Commands end with ; or \g.  
    65. Your MySQL connection id is 1  
    66. Server version: 5.0.77 Source distribution  
    67.   
    68. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
    69.   
    70. mysql> select  host, user from user;  
    71. +-----------+------------------+  
    72. | host      | user             |  
    73. +-----------+------------------+  
    74. | %         | admin            |  
    75. | localhost | admin            |  
    76. | localhost | horde            |  
    77. | localhost | pma_OBBVuV2L3mjn |  
    78. +-----------+------------------+  
    79. 4 rows in set (0.00 sec)  
    80.   
    81. -- 因为我数据库中没有root,换为admin了  
    82. mysql> UPDATE user SET Password=PASSWORD('******') where USER='admin';  
    83. Query OK, 2 rows affected (0.02 sec)  
    84. Rows matched: 2  Changed: 2  Warnings: 0  
    85.   
    86. mysql> FLUSH PRIVILEGES;  
    87. Query OK, 0 rows affected (0.02 sec)  
    88.   
    89. mysql> quit;  
    90. Bye  
    91. [root@INOTRADE ~]# /etc/init.d/mysqld restart  
    92. STOPPING server from pid file /var/run/mysqld/mysqld.pid  
    93. 120221 05:08:02  mysqld ended  
    94.   
    95. Stopping MySQL:                                            [  OK  ]  
    96. Starting MySQL:                                            [  OK  ]  
    97. [1]+  Done                    mysqld_safe --user=mysql --skip-grant-tables --skip-networking  
    98.   
    99. // 至此, 重启后就可以正常登录了  
    100. [root@INOTRADE ~]# mysql -uadmin -p******  
    101. Welcome to the MySQL monitor.  Commands end with ; or \g.  
    102. Your MySQL connection id is 3  
    103. Server version: 5.0.77 Source distribution  
    104.   
    105. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
    106.   
    107. mysql> show databases;  
    108. +-------------------------+  
    109. | Database                |  
    110. +-------------------------+  
    111. | information_schema      |  
    112. | *******                 |  
    113. | horde                   |  
    114. | mysql                   |  
    115. +-------------------------+  
    116. 7 rows in set (0.01 sec)  
    117.   
    118. mysql> use ********;  
    119. Reading table information for completion of table and column names  
    120. You can turn off this feature to get a quicker startup with -A  
    121.   
    122. Database changed  
    123. mysql> show tables;  
    124. +------------------------------+  
    125. | Tables_in_CQT_AMS            |  
    126. +------------------------------+  
    127. | T_ALM_APPLICATION            |  
    128. | *****************            |  
    129. | T_SYS_ROLE                   |  
    130. | T_SYS_USER_INFO              |  
    131. | T_SYS_USER_ROLE              |  
    132. +------------------------------+  
    133. 22 rows in set (0.00 sec)  
    134.   
    135. mysql> quit  
    136. Bye  
    137. [root@INOTRADE ~]#  
posted @ 2016-07-20 19:34  旧巷里的旧少年  阅读(1705)  评论(0编辑  收藏  举报