How to reset the password when you forget the root password of MySQL database on the cloud server?

LauraOSC 2021-02-23 16:19:15
reset password forget root password

modify Linux In the system MySQL Database root password
If you forget MySQL database root User's password , You can modify the configuration file , Skip password on login , Then change the password in the database . The default user of general database is root.
1. Execute the following command , edit MySQL Database my.cnf The configuration file .
vim /etc/my.cnf
notes :my.cnf The path of the configuration file is based on the actual environment .
2. stay \[mysqld\] Add the following under the field , Then save to exit .
3. Execute the following command , restart MySQL service .
/etc/init.d/mysqld restart
notes :MySQL The startup script path is based on the actual environment .
4. Execute the following command , Log in to the database .
notes :MySQL The command path is based on the actual environment .
5. In turn, execute as follows SQL sentence , Update the password .
USE mysql;
UPDATE user SET Password = password ('\[$Password\]') WHERE User = 'root';
flush privileges;
notes :\[$Password\] For new password , It is not recommended that the new password be “123456”, This password is too simple , Passwords need to meet password complexity requirements , You need a combination of uppercase and lowercase letters and numbers , The minimum length is 8 position , According to this password policy , Set the password .
perform UPDATE user SET Password = password ('\[$Password\]') WHERE User = 'root'; Report a mistake later ERROR 1054(42S22) Unknown column 'password' in ‘field list’
The reason for the mistake is 5.7 Version on mysql There is no password This field ,password Field changed to authentication_string  ,
namely :UPDATE user SET authentication_string = password ('mimimimi') WHERE User = 'root';
6. Edit again /etc/my.cnf The configuration file , Delete or annotate section 2 Step added skip-grant-tables.
7. Execute the following command , restart MySQL service .
/etc/init.d/mysqld restart
8. Log in to the database with your new password , Confirm normal login .


  1. 头条面试官:说说Kafka的消费者提交方式,怎么实现的
  2. 什么是HTTPS以及如何实施HTTPS?
  3. vue使用sdk进行七牛上传
  4. k8s-dns
  5. JavaScript 邮箱验证 - 正则验证
  6. k8s-dashboard
  7. HashMap连环问你能答出几道?
  8. Where does memory overflow occur in the JVM? What are the reasons for this?
  9. How many questions can you answer?
  10. k8s-cronjob
  11. spring注解--Transactional
  12. k8s-cert
  13. Will the Spring Festival holiday be extended to February 27 in 2021? Here comes the response
  14. Headline Interviewer: talk about Kafka's consumer submission method, how to achieve it
  15. 【k8s集群】搭建步骤
  16. k8s-kubeadm
  17. k8s-etcd
  18. What is HTTPS and how to implement it?
  19. Java中使用HashMap改进查找性能
  20. maven发布jar包运行时找不到类问题
  21. J2EE
  22. Vue uses SDK to upload seven cows
  23. k8s-dns
  24. JavaScript mailbox verification - regular verification
  25. k8s-dashboard
  26. How many questions can you answer?
  27. Spring annotation -- transactional
  28. [k8s cluster] construction steps
  29. k8s-kubeadm
  30. k8s-etcd
  31. Using HashMap to improve search performance in Java
  32. There is no class problem when Maven publishes jar package
  33. JavaScriptBOM操作
  34. J2EE
  35. k8s-prometheus-memory
  36. k8s-prometheus disk
  37. k8s-prometheus
  38. JavaScript BOM operation
  39. k8s-prometheus-memory
  40. k8s-prometheus disk
  41. k8s-prometheus
  42. Linux Disk Command
  43. Linux FS
  44. 使用docker-compose &WordPress建站
  45. Linux Command
  46. This time, thoroughly grasp the depth of JavaScript copy
  47. Linux Disk Command
  48. Linux FS
  49. Using docker compose & WordPress to build a website
  50. Linux Command
  51. 摊牌了,我 HTTP 功底贼好!
  52. shiro 报 Submitted credentials for token
  53. It's a showdown. I'm good at it!
  54. Shiro submitted credentials for token
  55. Linux Stress test
  56. Linux Root Disk Extension
  57. Linux Stress test
  58. Linux Root Disk Extension
  59. Redis高级客户端Lettuce详解
  60. springboot学习-综合运用(一)