Home Operation and Maintenance Linux Operation and Maintenance What to do if you forget your MySQL password in Linux

What to do if you forget your MySQL password in Linux

Mar 11, 2020 am 10:46 AM
linux mysql forget the password Solution

What to do if you forget your MySQL password in Linux

What to do if you forget your MySQL password in Linux

##1. First edit the /etc/my.cnf file

vim /etc/my.cnf
Copy after login
Copy after login

Add a line to configure skip-grant-tables in the file

For example, add it to this location

# read_rnd_buffer_size = 2M 
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
Copy after login

Then save and exit

2. Restart the mysql service

service mysqld restart
Copy after login
Copy after login

so that you can skip verification and enter mysql directly

3. Enter mysql

mysql
Copy after login

4. Execute the sql statements in sequence

>use mysql;    更改数据库
>UPDATE user SET PASSORD =password('你要设定的新密码') WHERE USER= 'root';  重设密码
>flush privileges;  刷新MySQL的系统权限相关表,以防止更改后拒绝访问;或或者重启MySQL服务器
>quit;
Copy after login

Note:

If you reset the password, an error message will be reported (ERROR 1054 (42S22): Unknown column 'PASSORD' in 'field list')

Use

>update mysql.user set authentication_string=password('你要设定的新密码') where user='root' ;
Copy after login

5. Edit the /etc/my.cnf file again

vim /etc/my.cnf
Copy after login
Copy after login

Remove the skip-grant-tables configuration, save and exit

6. Restart the mysql service

service mysqld restart
Copy after login
Copy after login

At this point, you can log in with the new password!

mysql -uroot -p
Copy after login

This article comes from the PHP Chinese website,

Linux system tutorial column, please continue to pay attention to this column for more related tutorials!

The above is the detailed content of What to do if you forget your MySQL password in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

How to compile vscode How to compile vscode Apr 16, 2025 am 07:51 AM

Compiling code in VSCode is divided into 5 steps: Install the C extension; create the "main.cpp" file in the project folder; configure the compiler (such as MinGW); compile the code with the shortcut key ("Ctrl Shift B") or the "Build" button; run the compiled program with the shortcut key ("F5") or the "Run" button.

How to automatically type vscode How to automatically type vscode Apr 16, 2025 am 07:30 AM

By using shortcut keys or configuration settings, you can implement automatic code typography in Visual Studio Code: Shortcut key typography: Windows/Linux: Ctrl K, Ctrl F; macOS: Cmd K, Cmd F Configuration Settings Typeset: Search and enable "editor.formatOnType", automatically type the current line every time you type a character Advanced typography options: Customize typography rules (e.g., indent size, line length), and select the desired typography (e.g., Prettier, ESLint)

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

How to set shortcut keys for sublime How to set shortcut keys for sublime Apr 16, 2025 am 09:15 AM

To set the shortcut keys for Sublime Text, follow these steps: Open the shortcut key settings file Key Bindings - User. Add shortcut key settings using the format { "keys": ["key combination"], "command": "command" }. Save changes. Reload the shortcut key settings for the changes to take effect.

How to enlarge fonts with vscode How to enlarge fonts with vscode Apr 16, 2025 am 07:45 AM

The methods to enlarge fonts in Visual Studio Code are: open the settings panel (Ctrl, or Cmd,). Search and adjust "Font Size". Choose "Font Family" with the right size. Install or select a theme that provides the right size. Use keyboard shortcuts (Ctrl or Cmd) to enlarge the font.

How to format json with vscode How to format json with vscode Apr 16, 2025 am 07:54 AM

The ways to format JSON in VS Code are: 1. Use shortcut keys (Windows/Linux: Ctrl Shift I; macOS: Cmd Shift I); 2. Go through the menu ("Edit" > "Format Document"); 3. Install JSON formatter extensions (such as Prettier); 4. Format manually (use shortcut keys to indent/extract blocks or add braces and semicolons); 5. Use external tools (such as JSONLint and JSON Formatter).

See all articles