MySQL user password modification and permission restriction settings

Source: Internet
Author: User

Changing the password in mysql generally refers to modifying the root password. If it is another user's password, we can modify it directly using phpmyadmin, next, I will introduce how to change the password and set user permissions.

Use phpmyadmin to change the root password

It is very convenient to use phpmyadmin to change the Mysql root Password. After installing and configuring phpmyadmin, first log on to the management interface, click the Change Password link on the right, and enter the new Mysql root Password you want to modify, click execute,


Note that phpmyadmin does not allow empty Logon of Mysql's root password by default. If you accidentally select an empty password on the password modification page, you need to modify the phpmyadmin configuration file so that you can log on to phpmyadmin again to change the mysql root Password. Next time, I will explain how to modify it.


Input Using mysqladmin:

Mysqladmin-u root-p oldpassword newpasswd

After executing this command, you need to enter the original root password, so that the root password will be changed to newpasswd. Similarly, if MySQL or you cannot execute mysqladmin, this method is invalid, and mysqladmin cannot clear the password.
 

The following methods are used at the MySQL prompt and must have the root permission of MySQL.


Method 3:

The Code is as follows: Copy code

Mysql> insert into mysql. user (Host, User, Password) VALUES ('%', 'system', PASSWORD ('manager'); mysql> FLUSH PRIVILEGES

Specifically, this is to add a user with the username system and Password manager. Be sure to use the PASSWORD function, and then use flush privileges for confirmation.

Method 4:

The REPLACE statement is used as follows:

The Code is as follows: Copy code

Mysql> replace into mysql. user (Host, User, Password) VALUES ('%', 'system', PASSWORD ('manager'); mysql> FLUSH PRIVILEGES

Method 5:

Use the set password statement:
 

The Code is as follows: Copy code

Mysql> set password for system @ "%" = PASSWORD ('manager ');

You must also use the PASSWORD () function, but do not need to use flush privileges for confirmation.

Root password retrieval in linux


1. First confirm that the server is in a secure state, that is, no one can connect to the MySQL database at will.
Because, during the resetting of the MySQL root Password, the MySQL database is completely out of password-free
Other users can log on to and modify MySQL information as needed. You can use
The external port is closed, and Apache and all user processes are stopped to implement server quasi-security.
Status. The safest status is to operate on the server Console and unplug the network cable.
2. Modify MySQL Logon Settings:
# Vi/etc/my. cnf
In the [mysqld] section, add skip-grant-tables.
For example:

The Code is as follows: Copy code
[Mysqld]
Datadir =/var/lib/mysql
Socket =/var/lib/mysql. sock
Skip-grant-tables

Save and exit vi.
3. Restart mysqld

The Code is as follows: Copy code
#/Etc/init. d/mysqld restart
Stopping MySQL: [OK]
Starting MySQL: [OK]

4. log on to and modify the MySQL root Password

The Code is as follows: Copy code
#/Usr/bin/mysql
Welcome to the MySQL monitor. Commands end with; or g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help; 'or 'H' for help. Type 'C' to clear the buffer.
Mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-
Database changed
Mysql> UPDATE user SET Password = password ('new-password') WHERE User = 'root ';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
Mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
Mysql> quit
Bye

5. Modify the MySQL Logon Settings.
# Vi/etc/my. cnf
Delete the skip-grant-tables added to the [mysqld] section.
Save and exit vi.
6. Restart mysqld

The Code is as follows: Copy code
#/Etc/init. d/mysqld restart
Stopping MySQL: [OK]
Starting MySQL: [OK]

Work for fun, Live for love!


Retrieve mysql password in windows


Method 2:

Create pwdhf.txt in the installation directory of MySQL, and enter the text: set password for 'root' @ 'localhost' = PASSWORD ('*****');

The red part shows the new password to be set.
Use windows service management tools or task manager to stop the MySQL service (task manager K drops the mysqld-nt process)
Doscommand prompt to the bin directory under the MySQL installation directory. For example, my directory is D: Program FilesMySQLMySQL Server 5.1bin.
Then run: mysqld-nt -- init-file = ../pwdhf.txt
After the execution is complete, stop the MySQL database service (Job Manager K drops the mysqld-nt process), and then start MYSQL again in normal mode.

How to Set access restrictions in MySql


Go to the Mysql execution directory (usually c: mysql in ). Enter mysqld-mongoware.exe and mysql -- user = root mysql. Otherwise, you cannot add new users. Go to the mysql> prompt to perform the operation.

Suppose we want to create a super user with the username system and user password manager.

Method 1:

Use the Grant command for authorization. The input code is as follows:

The Code is as follows: Copy code
Mysql> grant all privileges on *. * TO system @ localhost identified by 'manager' with grant option;

Display: Query OK, 0 rows affected (0.38 sec)

Method 2:

Set each permission of a user:

The Code is as follows: Copy code

Mysql> insert into user VALUES ('localhost', 'system', PASSWORD ('manager'), 'y ', 'y ', 'y ');

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.