Home Database Mysql Tutorial How to change mysql database password under linux? How to change database password in Linux

How to change mysql database password under linux? How to change database password in Linux

Oct 22, 2018 pm 05:23 PM
linux mysql database change Password

The content of this article is to introduce how to change the mysql database password under Linux? How to change database password in Linux. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

How to modify Mysql under Linux (root password and modify root login permissions

The modified users are listed as root.

1. Know the root password of the original myql database;

①: Enter mysqladmin -u root -p password "new password" at the terminal command line and press Enter, Enter password: /* Enter the original old password*/
②: Log in to the mysql system to modify, mysql -uroot -p Enter password: /* Enter the original password */

mysql>use mysql;
mysql> update user set password=password(“新密码”) where user=‘root’;        /* 密码注意大小写 */
mysql> flush privileges;
mysql> exit;
service mysqld/mysql statusservice mysqld/mysql restart/start
Copy after login
Copy after login

Then use the new password you just entered to log in.

2. I don’t know the original myql root password;
First of all, you must have root permissions on the operating system. If you don’t even have root permissions on the system, consider rooting the system first and then take the following steps. . Similar to logging in to the system in safe mode.

You need to stop the mysql service first. There are two situations. One can use service mysqld stop,

The other is /etc/init.d /mysqld stop

When prompted that mysql has stopped, proceed to the next step Shutting down MySQL. SUCCESS!

Enter on the terminal command line

mysqld_safe --skip-grant-tables &         /* 登录mysql系统 */
Copy after login
Copy after login
Copy after login
Copy after login

Enter mysql to log in to the mysql system

mysql> use mysql;
mysql> UPDATE user SET password=password(“新密码”) WHERE user=‘root’;      /* 密码注意大小写 */
mysql> flush privileges;
mysql> exit;
Copy after login
Copy after login

Restart the mysql service

The new root password will be set successfully.

3. Modify root login permissions

After you modify the root password , this situation is very likely to occur

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

This is because the root login permission is insufficient , the specific modification method is as follows

You need to stop the mysql service first. There are two situations here. One can use service mysqld stop,

The other is /etc/init.d/mysqld stop

When prompted that mysql has stopped, proceed to the next step Shutting down MySQL. SUCCESS!

Enter mysql on the terminal command line to log in to the mysql system

mysqld_safe --skip-grant-tables &         /* 登录mysql系统 */
Copy after login
Copy after login
Copy after login
Copy after login

Then restart the mysql service.


First sentence: Log in as the authorized user root

Second sentence: Select the mysql library

Third sentence: View the mysql library The host value of the user table (that is, the host/IP name for connection access)
The fourth sentence: Modify the host value (add the host/IP address with the wildcard % content), of course you can also directly add the IP address
If there is an error in this step "ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'" It means that the record exists, skip this step
The fifth sentence: Refresh the MySQL system permissions related table
Sixth sentence: When checking the user table again, there are modifications. .
Restart the mysql service to complete.

MariaDB sets initialization password and changes password

Method 1:

mysql>use mysql;
mysql>update user set host = ‘%’ where user = ‘root’;
mysql>select host, user from user;
mysql> flush privileges;
mysql> exit;
service mysqld/mysql statusservice mysqld/mysql restart/start
Copy after login
Copy after login

Method 2:

[root@localhost ~]# mysql
MariaDB[(none)]> UPDATE mysql.user SET password = PASSWORD(‘newpassword’) WHERE USER = ‘root’;
MariaDB[(none)]> FLUSH PRIVILEGES;
Copy after login
Copy after login

Method 3:

[root@localhost ~]# mysql
MariaDB[(none)]> SET password=PASSWORD(‘newpassward’);
Copy after login
Copy after login

If root has set a password, use the following method

[root@localhost ~]# mysqladmin -u root password ‘newpassword’
Copy after login
Copy after login



How to modify Mysql under Linux ( Root's password and modification of root login permissions

The modified users are listed as root.

1. Know the root password of the original myql database;

①: In the terminal Enter mysqladmin -u root -p password "new password" on the command line, press Enter password: /* Enter the original old password */

②: Log in to the mysql system to modify, mysql -uroot -p press Enter password: /* Enter the original password */

[root@localhost ~]#mysqladmin -u root -p ‘oldpassword’ password ‘newpassword’
Copy after login
Copy after login

Then use the new password you just entered to log in.


2. I don’t know the original myql root password;

First of all, you must have root permissions on the operating system. If you do not even have root permissions on the system, consider rooting the system first and then take the following steps. It is similar to logging in to the system in safe mode.


You need to first Stop the mysql service. There are two situations here. One can use service mysqld stop,

The other is /etc/init.d/mysqld stop

When prompted that mysql has stopped, proceed Next step: Shutting down MySQL. SUCCESS!

Enter

mysql>use mysql;
mysql> update user set password=password(“新密码”) where user=‘root’;        /* 密码注意大小写 */
mysql> flush privileges;
mysql> exit;
service mysqld/mysql statusservice mysqld/mysql restart/start
Copy after login
Copy after login

in the terminal command line

mysqld_safe --skip-grant-tables &         /* 登录mysql系统 */
Copy after login
Copy after login
Copy after login
Copy after login

Enter mysql to log in to the mysql system

mysql> use mysql;
mysql> UPDATE user SET password=password(“新密码”) WHERE user=‘root’;      /* 密码注意大小写 */
mysql> flush privileges;
mysql> exit;
Copy after login
Copy after login

Restart the mysql service

This way The new root password has been set successfully.

3. Modify root login permissions

After you modify the root password, this situation is likely to occur

ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
Copy after login

This It is because the root login permission is insufficient. The specific modification method is as follows

You need to stop the mysql service first. There are two situations here. One can use service mysqld stop,

The other is /etc/ init.d/mysqld stop

When prompted that mysql has stopped, proceed to the next step Shutting down MySQL. SUCCESS!

Enter on the terminal command line

mysqld_safe --skip-grant-tables &         /* 登录mysql系统 */
Copy after login
Copy after login
Copy after login
Copy after login

Enter mysql to log in to mysql System

mysql>use mysql;
mysql>update user set host = ‘%’ where user = ‘root’;
mysql>select host, user from user;
mysql> flush privileges;
mysql> exit;
service mysqld/mysql statusservice mysqld/mysql restart/start
Copy after login
Copy after login

Then restart the mysql service.

The first sentence: Log in as the authorized user root

The second sentence: Select the mysql library

The third sentence: View the host of the user table in the mysql library Value (the host/IP name for connection access)

Fourth sentence: Modify the host value (add the host/IP address with wildcard % content), of course you can also directly add the IP address

如果这步出错"ERROR 1062 (23000): Duplicate entry ‘%-root’ for key ‘PRIMARY’" 由说明该记录有了,跳过这步

第五句:刷新MySQL的系统权限相关表

第六句:再重新查看user表时,有修改。。

重起mysql服务即可完成。

MariaDB设置初始化密码及修改密码
方法1:

[root@localhost ~]# mysql
MariaDB[(none)]> UPDATE mysql.user SET password = PASSWORD(‘newpassword’) WHERE USER = ‘root’;
MariaDB[(none)]> FLUSH PRIVILEGES;
Copy after login
Copy after login

方法2:

[root@localhost ~]# mysql
MariaDB[(none)]> SET password=PASSWORD(‘newpassward’);
Copy after login
Copy after login

方法3:

[root@localhost ~]# mysqladmin -u root password ‘newpassword’
Copy after login
Copy after login

如果root已经设置过密码,采用如下方法

[root@localhost ~]#mysqladmin -u root -p ‘oldpassword’ password ‘newpassword’
Copy after login
Copy after login

The above is the detailed content of How to change mysql database password under linux? How to change database 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)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

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.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

See all articles