解决MySQL登录报ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)的问题

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq_32786873/article/details/79225039

使用mysql -uroot -p,然后输入密码登录mysql时,出现了如下错误:

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

一般这个错误是由密码错误引起,解决的办法自然就是重置密码

解决方案如下:

1.停止mysql数据库:systemctl stop mysqld

2.用以下命令启动MySQL,以不检查权限的方式启动:

mysqld --skip-grant-tables &

此时又报了一个错误:2018-02-01T02:52:55.093724Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

执行命令:mysqld --user=root --skip-grant-tables &

3.登录mysql:mysql -uroot或mysql

4.更新root密码

mysql5.7以下版本:UPDATE mysql.user SET Password=PASSWORD('123456') where USER='root';

mysql5.7版本:UPDATE mysql.user SET authentication_string=PASSWORD('123456') where USER='root';

5.刷新权限:flush privileges;

6.退出mysql:exit或quit

7.使用root用户重新登录mysql

mysql -uroot -p

Enter password:<输入新设的密码123456>


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

04-24

用户名和密码没有错!球各路大仙们指点!rnrnorg.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configurernINFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/weibosystem]rn四月 24, 2012 5:24:50 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configurernINFO: HHH000046: Connection properties: user=root, password=****rn四月 24, 2012 5:24:50 下午 org.hibernate.engine.jdbc.internal.JdbcServicesImpl configurernWARN: HHH000342: Could not obtain connection to query metadata : Access denied for user 'root'@'localhost' (using password: YES)rn四月 24, 2012 5:24:50 下午 org.hibernate.dialect.Dialect rnINFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialectrn四月 24, 2012 5:24:50 下午 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreationrnINFO: HHH000422: Disabling contextual LOB creation as connection was nullrn四月 24, 2012 5:24:50 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateServicernINFO: HHH000399: Using default transaction strategy (direct JDBC transactions)rn四月 24, 2012 5:24:50 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory rnINFO: HHH000397: Using ASTQueryTranslatorFactoryrn四月 24, 2012 5:24:51 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptionsrnWARN: SQL Error: 1045, SQLState: 28000rn四月 24, 2012 5:24:51 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptionsrnERROR: Access denied for user 'root'@'localhost' (using password: YES)

Access denied for user 'root'@'localhost' (using password Yes

09-25

08:43:20,125 WARN JDBCExceptionReporter:71 - SQL Error: 1045, SQLState: 28000rn08:43:20,140 ERROR JDBCExceptionReporter:72 - Access denied for user 'root'@'localhost' (using password: YES)rn08:43:20,140 WARN SettingsFactory:103 - Could not obtain connection metadatarnjava.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)rn at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2901)rn at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:773)rn at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3612)rn at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1204)rn at com.mysql.jdbc.Connection.createNewIO(Connection.java:1699)rn at com.mysql.jdbc.Connection.(Connection.java:408)rn at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:270)rn at java.sql.DriverManager.getConnection(DriverManager.java:582)rn at java.sql.DriverManager.getConnection(DriverManager.java:154)rn at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:291)rn at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:277)rn at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:259)rn at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:240)rn at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)rn at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)rn at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)rn at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)rn at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)rn at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)rn at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)rn at org.apache.catalina.core.StandardService.start(StandardService.java:525)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:595)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)rn非常蛋疼的问题,导入别人的项目时报这个错误。rn网上查了原因,无非三种:账户密码错误,权限不够,要么是架包,但我三种都试过了,还是报错。rn现贴下hibernate配置rn rn MySQL_JDBCrn rn rn jdbc:mysql://localhost:3306/db_eshop?useUnicode=true&characterEncoding=gb2312rn rn rootrn 123rn rn com.mysql.jdbc.Driverrn rn rn org.hibernate.dialect.MySQLDialectrn rn有哪位大侠能指正?

windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes

05-15

windowsxp系统 mysql-5.0.11-beta-win32rn提示:1045 access denied for user 'root'@'localhost' using password yesrn前几天都好好的,昨天没弄,结果今天晚上过来提示上面的这个错误,重启mysql还是不可以rn网上的方法看了几个但是不知道怎么弄rn[b]方法一:[/b] rn# /etc/init.d/mysql stop rn# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & rn# mysql -u root mysql rnmysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; rnmysql> FLUSH PRIVILEGES; rnmysql> quit rn# /etc/init.d/mysql restart rn# mysql -uroot -p rnEnter password: rnmysql> rn[b]方法二:[/b] rn直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码: rn# mysql -udebian-sys-maint -p rnEnter password: rnmysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; rnmysql> FLUSH PRIVILEGES; rnmysql> quit rn# mysql -uroot -p rnEnter password: rnmysql> rnrn内容来自: 脚本之家 www.jb51.net rnrn[b]另一个方法[/b]rnWindows:rnrn1. 管理员登陆系统,停止mysql服务或者结束mysqld-nt进程rn2. 进入命令行,来到mysql的安装目录.假设安装目录为 d:\mysql\ , CMD进入命令行rn3. 运行 d:\mysql\bin\mysqld-nt --skip-grant-tables 启动mysql,关闭权限的检查rn4. 运行 d:\mysql\bin\mysqladmin -u root flush-privileges password "newpassword" 重设root密码rn5. 重新启动mysql服务rnrn第4步也可以直接修改mysql表,所用到的SQL语句同linux部分,这里就不再重复了.rnrn请不要乱给答案否则不给分rn一定要试验过的成功经验,谢谢!

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试