Linux下mysql数据库root无法登录的情况
今天安装lnmp环境后用mysql -u root -p连接密码后出现错误
Access denied for user 'root'@'localhost' (using password: YES)
然后我就用 /etc/init.d/mysql stop 先去停止数据库
然后用安全模式 mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 进入数据库
然后用SQL语句修改root权限 UPDATE user SET Password=PASSWORD('我的密码') where USER='root';
改完了后 重新刷新权限 FLUSH PRIVILEGES; 然后quit退出
然后重启数据库就行了 /etc/init.d/mysql restart
[root@967b0e11e627 default]# mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [root@967b0e11e627 default]# /etc/init.d/mysql stop Shutting down MySQL. SUCCESS! [root@967b0e11e627 default]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & [1] 91761 [root@967b0e11e627 default]# 160618 11:54:54 mysqld_safe Logging to '/usr/local/mysql/var/967b0e11e627.err'. 160618 11:54:55 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var [root@967b0e11e627 default]# mysql -u root mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.48-log Source distribution Copyright (c) 2000, 2016, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.02 sec) mysql> UPDATE user SET Password=PASSWORD('20150125') where USER='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye [root@967b0e11e627 default]# /etc/init.d/mysql restart Shutting down MySQL.160618 11:55:53 mysqld_safe mysqld from pid file /usr/local/mysql/var/967b0e11e627.pid ended SUCCESS! Starting MySQL.. SUCCESS! [1]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking [root@967b0e11e627 default]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.48-log Source distribution Copyright (c) 2000, 2016, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) mysql> exit Bye
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战