Linux mysql 5.7: 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 for user ‘root‘@‘localhost‘ (using password: NO)
[root@DB-Server tmp]# mysql -u root mysql
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
安装过程中没有设置过root密码,不清楚root密码,搜索了网上一些资料,大致有下面一些情况:
1:有些博客说root的随机密码位于/root/.mysql_secret中,但是我这个版本根本没有/root/.mysql_secret文件。搜索到一篇文章,大意如下所示(没有确认)。到现在也没有明白,我这个版本为什么没有生成这个文件?
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO) :表示没有生成root的临时密码
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) :表示生成了root的临时密码。
2:有些资料说root的默认密码为空,经过确认那是以前的老版本,Mysql 5.6及以后版本出处于安全考虑,root密码已经不为空了。
另外,我在官网论坛居然发现有很多人遇到类似问题ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
解决方法:
首先停掉mysql服务器
[root@DB-Server init.d]# /etc/rc.d/init.d/mysql stop
Shutting 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日志,发现也无其它异常信息。没有弄明白该会话窗口为啥会出现无响应状态。
tail -200 /var/lib/mysql/DB-Server.err | more
2014-07-22 14:59:41 9346 [Note] Shutting down plugin ‘binlog‘
2014-07-22 14:59:41 9346 [Note] /usr/sbin/mysqld: Shutdown complete
140722 14:59:41 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended
140722 14:59:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2014-07-22 14:59:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timesta
mp server option (see documentation for more details).
2014-07-22 14:59:47 9516 [Note] Plugin ‘FEDERATED‘ is disabled.
2014-07-22 14:59:47 9516 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-07-22 14:59:47 9516 [Note] InnoDB: The InnoDB memory heap is disabled
2014-07-22 14:59:47 9516 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-07-22 14:59:47 9516 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-07-22 14:59:47 9516 [Note] InnoDB: Using Linux native AIO
2014-07-22 14:59:47 9516 [Note] InnoDB: Using CPU crc32 instructions
2014-07-22 14:59:47 9516 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-07-22 14:59:47 9516 [Note] InnoDB: Completed initialization of buffer pool
2014-07-22 14:59:47 9516 [Note] InnoDB: Highest supported file format is Barracuda.
2014-07-22 14:59:47 9516 [Note] InnoDB: 128 rollback segment(s) are active.
2014-07-22 14:59:47 9516 [Note] InnoDB: Waiting for purge to start
2014-07-22 14:59:47 9516 [Note] InnoDB: 5.6.19 started; log sequence number 1626087
2014-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 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 ‘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(‘p12#456‘)
-> where user=‘root‘ and host=‘root‘ or host=‘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
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
[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 ‘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(‘p12#456‘);
至此问题解决,但是还有不少地方有些疑惑,为啥出现这个错误? 其实这么多资料都只是说了解决方法,但是都回避了问题的原因。
Linux mysql 5.7: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
标签:nat 了解 document image format xpl completed target 5.7
小编还为您整理了以下内容,可能对您也有帮助:
mysql问题:access denied for user 'root@localhost'(using password: YES)
错误1045(28000):用户'root'@'localhost'(使用密码:YES)拒绝访问
首先解析此英文:ERROR
1045
(28000):
Access
denied
for
user
'root'@'localhost'
(using
password:
YES);解析的地方有两处:①Access
denied(拒绝访问);②using
password:NO/YES
1.
出现access
denied的原因有如下可能:
1)mysql的服务器停止
2)用户的端口号或者IP导致
3)mysql的配置文件错误----my.ini等文件
4)root用户的密码错误
若MySQL已经没有启动,重启MySQL服务器:net
start
mysql
若用户的端口号与IP(3306/3307)不一致,打开my.ini文件进行编辑。全部编辑替换为:
port=X
my.ini文件误输入无效内容,不知道到何处。复制替换该文件;有人已经对my.ini文件进行解释以及注释
root用户密码错误,
解决方案见下文
2.
出现
using
password的原因如下是:
不键入密码:
错误的密码:
解决方案:
到安装的MySQL的目录下,找my.ini文件;
在[mysqld]后添加skip-grant-tables(使用
set
password
for设置密码无效,且此后登录无需键入密码)
skip-grant-tables
#在my.ini,[mysqld]下添加一行,使其登录时跳过权限检查
尽量少操作
重启MySQL服务器。
登录mysql,键入mysql
–uroot
–p;直接回车(Enter)
键入无效set
password
for
‘root’@‘localhost’=password(‘123456’);
在my.ini文件添加从此后无需键入密码
再把my.ini的skip-grant-tables删除,然后重启MySQL服务器:net
stop
mysql
;net
start
mysql;
再次进行设置密码:set
password
for
‘root’@‘localhost’=password(‘123456’);
设置密码成功。。。
注:skip-name-resolv
#禁止MySQL对外部连接进行DNS解析,使用这一选项可以消除MySQL进行DNS解析的时候。但是需要注意的是,如果开启该选项,则所有远程主机连接授权都要使用IP地址方式了,否则MySQL将无法正常处理连接请求!
进入mysql出现 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y ES)
root1、先在电脑上打开软件,可从电脑管家里面启动。然后点击【连接手机】——看到【请用USB数据线 连接手机】时候连上数据线。然后手机进入【设置】——【开发者选项打开】——【USB调试开启】——接着在弹出的界面上, 点击【已经 开启USB调试】就行。之后手机上会显示【是否允US B调试】——【确定】。 2、等待成功连接 手机和电脑应用宝后,它会自己装好驱动,应用主界面左上角会看到手机品牌型号。点击右上角的【工具箱】——【解除root】——解除好了会显示已成功解除权限。权限就解除完毕了。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
1、开始菜单->控制面板->管理工具->服务,找到Mysql服务停掉。
2、右击我的电脑->管理->服务与应用->服务,找到mysql服务停掉。
3、Ctrl+Alt+Delete->启动服务管理器->服务,找到mysql服务停掉。
mysql ERROR 1045 (28000): 错误解决办法
1、找到配置文件my.ini ,然后将其打开,可以选择用记事本打开
2、打开后,搜索mysqld关键字。找到后,在mysqld下面添加skip-grant-tables,保存退出。
3、保存后重启mySQL
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using passwor:NO)
解决方法一:运行MySQL Server Instance Configuration Wizard,在“Please set the security options”一步,勾上“Create An Anonymous Account”
解决方法二:在命令行中,运行:...\depot> mysql -u <输入用户名,例如root> -p depot_development <db/create.sql,这时会提示你输入密码,输入即可。其中选项-p表示要求输入密码。追问你的解决方法相当于是添加了一个可以匿名访问的用户(“mysql -u root -p”这种带密码的连接我是可以连接的。)。我输入“mysql -v”时候正常情况下应该只输出mysql的版本信息,现在按照你的建议更改之后,不仅可以显示版本信息,还连接上了数据库,这会造成安全问题。怎么不让它连接呢