CentOS 下mysql ERROR 1045: Access denied for user: '

it mysql error1045 centos6.5

案例环境:

             操作系统:CentOS 6.5

数据库版本 : Mysql 5.6.19 64 bit

昨天在学习python,安装部署Mysql 5.6.19 64bit 版本的数据库时,数据库安装成功了,但是使用root登录时遇到了ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)错误. 如下所示

[root@DB-Server tmp]# rpm -ivh MySQL-server-5.6.19-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
[root@DB-Server tmp]# rmp -ivh MySQL-client-5.6.19-1.rhel5.x86_64.rpm 
-bash: rmp: command not found
[root@DB-Server tmp]# rpm -ivh MySQL-client-5.6.19-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[root@DB-Server tmp]# /etc/rc.d/init.d/mysql status
MySQL is not running[FAILED]
[root@DB-Server tmp]# /etc/rc.d/init.d/mysql start
Starting MySQL.[  OK  ]
[root@DB-Server tmp]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied 'localhost' (using password: NO)
[root@DB-Server tmp]# mysql -u root mysql
ERROR 1045 (28000): Access denied 'localhost' (using password: NO)

 

在网上找了很多资料,都没有解决好,网上的资料都一样,你抄我的我抄你的,现在我把我的处理方案晒一晒:

第一:首先停掉mysql服务器, 然后使用mysqld_safe命令在启动mysql,更新root账号的密码,--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。--skip-networking :跳过TCP/IP协议,只在本机访问(从网上有些资料看,这个选项不是必须的(可以不用)。

[root@DB-Server init.d]# /etc/rc.d/init.d/mysql stop
 Shutting down MySQL..[ OK ]
[root@DB-Server init.d]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[2] 9396
[root@DB-Server init.d]# 140722 14:59:46 mysqld_safe Logging to '/var/lib/mysql/DB-Server.err'.
140722 14:59:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

执行上面命令后,此会话窗口会出现无反应的状态,在按一下enter键,就ok.

第二 :使用 mysql -u root mysql 登录数据库,设置用户名和密码。

[root@DB-Server init.d]# 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.6.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type '\c' to clear the current input statement.
mysql> select Host, User, Password,password_expired
    -> from user
    -> where user='localhost';
+-----------+------+-------------------------------------------+------------------+
| Host      | User | Password                                  | password_expired |
+-----------+------+-------------------------------------------+------------------+
| localhost | root | *A848DE7CCD839E924921BEE41711991DDA0D529E | Y                |
+-----------+------+-------------------------------------------+------------------+
1 row in set (0.00 sec)
mysql> update user set password=PASSWORD('p12#456')
    -> where user='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

       新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

第三:启动数据库

[root@DB-Server init.d]# /etc/rc.d/init.d/mysql restart
Shutting down MySQL..140722 15:02:27 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended
[  OK  ]
Starting MySQL.[  OK  ]
[2]-  Done                    mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@DB-Server init.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.19
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type '\c' to clear the current input statement.
mysql>

      至此问题解决。


相关推荐

你的评论

就没有什么想说的吗?

最新博客

关于我们 免责声明 移动版

©2017传客网    琼ICP备15003173号-2    

本站部分文章来源于互联网,版权归属于原作者。
本站所有转载文章言论不代表本站观点,如是侵犯了原作者的权利请发邮件联系站长(weishubao@126.com),我们收到后立即删除。
站内所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!

X