700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > linux ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

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

时间:2019-11-02 04:49:25

相关推荐

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

linux版本:CentOS release 5.6

64位操作系统

mysql数据库:5.5.18

输入mysql -u root -p,然后输入密码,回车后报错如下:

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

解决方法(转载)

原文网址:/kerrycode/p/3861719.html

[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 statusMySQL is not running[FAILED][root@DB-Server tmp]# /etc/rc.d/init.d/mysql startStarting MySQL.[ OK ][root@DB-Server tmp]# mysql -u root -pEnter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)[root@DB-Server tmp]# mysql -u root mysqlERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方法:

首先停掉mysql服务器

[root@DB-Server init.d]# /etc/rc.d/init.d/mysql stopShutting down MySQL..[ OK ]

然后使用mysqld_safe命令在启动mysql,更新root账号的密码

--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。

--skip-networking :跳过TCP/IP协议,只在本机访问(从网上有些资料看,这个选项不是必须的。可以不用)

[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

执行上面命令后,此会话窗口会出现无反应的状态,需要使用CTRL+C中断会话,检查/var/lib/mysql/DB-Server.err日志,发现也无其它异常信息。没有弄明白该会话窗口为啥会出现无响应状态。

ctrl+c 后如下结果:

tail -200 /var/lib/mysql/DB-Server.err | more-07-22 14:59:41 9346 [Note] Shutting down plugin 'binlog'-07-22 14:59:41 9346 [Note] /usr/sbin/mysqld: Shutdown complete140722 14:59:41 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended140722 14:59:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql-07-22 14:59:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).-07-22 14:59:47 9516 [Note] Plugin 'FEDERATED' is disabled.-07-22 14:59:47 9516 [Note] InnoDB: Using atomics to ref count buffer pool pages-07-22 14:59:47 9516 [Note] InnoDB: The InnoDB memory heap is disabled-07-22 14:59:47 9516 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins-07-22 14:59:47 9516 [Note] InnoDB: Compressed tables use zlib 1.2.3-07-22 14:59:47 9516 [Note] InnoDB: Using Linux native AIO-07-22 14:59:47 9516 [Note] InnoDB: Using CPU crc32 instructions-07-22 14:59:47 9516 [Note] InnoDB: Initializing buffer pool, size = 128.0M-07-22 14:59:47 9516 [Note] InnoDB: Completed initialization of buffer pool-07-22 14:59:47 9516 [Note] InnoDB: Highest supported file format is Barracuda.-07-22 14:59:47 9516 [Note] InnoDB: 128 rollback segment(s) are active.-07-22 14:59:47 9516 [Note] InnoDB: Waiting for purge to start-07-22 14:59:47 9516 [Note] InnoDB: 5.6.19 started; log sequence number 1626087-07-22 14:59:47 9516 [Note] /usr/sbin/mysqld: ready for connections.Version: '5.6.19' socket: '/var/lib/mysql/mysql.sock' port: 0 MySQL Community Server (GPL)

然后输入如下命令

[root@DB-Server init.d]# mysql -u root mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -AWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.19 MySQL Community Server (GPL)Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> select Host, User, Password,password_expired-> from user-> where user='root' and host='root' or host='localhost';+-----------+------+-------------------------------------------+------------------+| Host| User | Password | password_expired |+-----------+------+-------------------------------------------+------------------+| localhost | root | *A848DE7CCD839E924921BEE41711991DDA0D529E | Y|+-----------+------+-------------------------------------------+------------------+1 row in set (0.00 sec)mysql> update user set password=PASSWORD('root')-> where user='root' and host='root' or host='localhost';Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0

我在select用户表的时候结果为0 row ,也就是没有数据结果,需要用insert进行添加

insert into user set user='root’,ssl_cipher='',x509_issuer='',x509_subject='';

然后将其他字段添加上:

update user set Host=‘localhost’,select_priv=‘y', insert_priv=‘y',update_priv=‘y', Alter_priv=‘y’,delete_priv=‘y',create_priv=‘y',drop_priv=‘y',reload_priv=‘y',shutdown_priv=‘y',Process_priv=‘y',file_priv=‘y',grant_priv=‘y',References_priv=‘y',index_priv=‘y',create_user_priv=‘y',show_db_priv=‘y',super_priv=‘y',create_tmp_table_priv=‘y',Lock_tables_priv=‘y',execute_priv=‘y',repl_slave_priv=‘y',repl_client_priv=‘y',create_view_priv=‘y',show_view_priv=‘y',create_routine_priv=‘y',alter_routine_priv=‘y',create_user_priv=‘y’ where user=‘root’;

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

mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> quitBye[root@DB-Server init.d]# /etc/rc.d/init.d/mysql restartShutting down MySQL..140722 15:02:27 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended[ OK ]Starting MySQL.[ OK ][2]- Donemysqld_safe --user=mysql --skip-grant-tables --skip-networking[root@DB-Server init.d]# mysql -u root pERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)[root@DB-Server init.d]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.6.19Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

至此问题解决

另外,如果登录mysql数据库后执行脚本遭遇 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement,可以使用重新设置一次密码即可解决问题.

mysql>set password = password('root');

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。