search
HomeDatabaseMysql TutorialWhat should I do if I forget mysql password?

Solution: 1. Open the configuration file "my.cnf", add the "skip-grant-tables" statement under the "[mysqld]" item, and restart the MySQL service; 2. Execute "mysql -u root " command to log in to the database without a password; 3. Use the update command to reset the login password.

What should I do if I forget mysql password?

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

What should I do if I forget mysql password? Don’t be afraid, you can reset a new password through Reset password,

How to reset password

1. Modify the configuration file my.cnf, add skip-grant-tables under the configuration file [mysqld], restart the MySQL service to log in without a password

among them --skip-grant-tables The option means to skip the permission table authentication when starting the MySQL service. Once started, root connections to MySQL will not require a password (dangerous).

[mysqld]
skip-grant-tables

2. Connect to MySQL with the root user with an empty password, and change the root password

Log in to the MySQL database without a password:

[root@iZ235wguph2Z www]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 295
Server version: 5.0.56-log Source distribution
Copyright (c) 2000, 2017, 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.

Reset Password:

mysql> update user set password=password('123456') where User='root';
ERROR 1046 (3D000): No database selected
mysql> use mysql;
Database changed
mysql> update user set password=password('123456') 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> exit

3. Delete the skip-grant-tables option in my.cnf, and then restart the MySQL service.

The password of the root user of the MySQL database has been modified.

[Related recommendations: mysql video tutorial]

The above is the detailed content of What should I do if I forget mysql password?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Troubleshooting MySQL Corrupted Tables and Data RecoveryTroubleshooting MySQL Corrupted Tables and Data RecoveryJul 21, 2025 am 02:14 AM

Common causes of table corruption include system crashes, insufficient storage, file system errors, abnormal service termination and unstable storage engines. The detection methods include using the CHECKTABLE command, viewing error logs and regular checks. Repair methods include REPAIRTABLE command, myisamchk tool repair and recovery from backup. Notes include backup first and then operation, confirming the storage engine type, using professional tools, and monitoring server stability.

Optimizing MySQL for Real-time Dashboards and ReportingOptimizing MySQL for Real-time Dashboards and ReportingJul 21, 2025 am 02:12 AM

TooptimizeMySQLforreal-timedashboards,focusonsmartindexing,queryoptimization,schemadesign,andcaching.1)Useindexeswisely—createcompositeandcoveringindexeswhereneededbutavoidover-indexing.2)Optimizequeriesbyselectingonlynecessarycolumns,limitingresults

Securing MySQL Connections with SSL/TLS EncryptionSecuring MySQL Connections with SSL/TLS EncryptionJul 21, 2025 am 02:08 AM

Why do I need SSL/TLS encryption MySQL connection? Because unencrypted connections may cause sensitive data to be intercepted, enabling SSL/TLS can prevent man-in-the-middle attacks and meet compliance requirements; 2. How to configure SSL/TLS for MySQL? You need to generate a certificate and a private key, modify the configuration file to specify the ssl-ca, ssl-cert and ssl-key paths and restart the service; 3. How to force SSL when the client connects? Implemented by specifying REQUIRESSL or REQUIREX509 when creating a user; 4. Details that are easily overlooked in SSL configuration include certificate path permissions, certificate expiration issues, and client configuration requirements.

Implementing MySQL Database Governance FrameworksImplementing MySQL Database Governance FrameworksJul 21, 2025 am 02:06 AM

The key to implementing the MySQL database governance framework is to clarify the goals, sort out the status quo and select appropriate tools and strategies. 1. Permission control should follow the principle of minimum authority, use role management to unified authority allocation, and regularly audit permissions to reduce risks; 2. Introduce SQL audit platform to implement pre-online inspections, standardize changes processes and record historical changes to avoid unaudited high-risk operations; 3. Establish a performance monitoring system, covering basic and business indicators, set up a hierarchical alarm mechanism, and recommend the use of Prometheus Grafana to achieve visual monitoring; 4. Formulate a backup strategy that combines full and incremental quantities, regularly verify the effectiveness of backups and conducts recovery drills, establish an automatic backup and manual confirmation mechanism to prevent formalistic backups. The above four directions

Optimizing MySQL for Real-time Fraud DetectionOptimizing MySQL for Real-time Fraud DetectionJul 21, 2025 am 01:59 AM

TooptimizeMySQLforreal-timefrauddetection,configuresmartindexing,chooseInnoDBasthestorageengine,andtunesystemsettingsforhighthroughput.1)Usecompositeandcoveringindexestospeedupfrequentquerieswithoutover-indexing.2)SelectInnoDBforrow-levellocking,ACID

Optimizing MySQL Regular Expression SearchesOptimizing MySQL Regular Expression SearchesJul 21, 2025 am 01:59 AM

The key points of optimizing the performance of MySQL regular query include: 1. Avoid full table scanning, narrowing the search scope through ordinary WHERE conditions or simplifying regular expressions; 2. Optimizing regular writing methods, such as using ^abc instead of �c%, avoiding greedy matching; 3. Reasonable use of generating column indexes, preprocessing and storing regular logic, and improving query efficiency.

Optimizing MySQL Server Configuration VariablesOptimizing MySQL Server Configuration VariablesJul 21, 2025 am 01:58 AM

MySQL performance optimization requires adjusting server configuration variables to improve efficiency and stability. First, it is necessary to set the memory parameters reasonably, such as innodb_buffer_pool_size, no more than 70% to 80% of the physical memory, key_buffer_size, tmp_table_size, etc., selectively adjust according to the engine; secondly, optimize connection and concurrency parameters, such as max_connections to avoid connection bottlenecks, thread_stack controls thread resource occupation, and innodb_thread_concurrency matches the number of CPU cores; secondly, balance log and persistence performance, such as innodb_flush_log_at_trx_c

Real-time Data Replication from MySQL using DebeziumReal-time Data Replication from MySQL using DebeziumJul 21, 2025 am 01:55 AM

Debezium is an effective tool for real-time replication of MySQL. It captures data changes by parsing MySQL's binlog logs and pushes them to downstream systems such as Kafka. 1.Debezium is a log-based open source data change capture platform, suitable for MySQL because it can extract insert, update, and delete operations with low latency and low impact. 2. Preconditions include: MySQL5.7, setting binlog format to ROW, optional GTID, configuring replication user permissions, and installing Kafka and KafkaConnect. 3. The configuration needs to provide connection information JSON file, specify the database address, user, listened library table, snapshot mode and other parameters.

See all articles

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),