Home > Database > Mysql Tutorial > body text

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

青灯夜游
Release: 2018-10-22 17:23:56
forward
13244 people have browsed it

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

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

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!

source:csdn.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!