To secure the initial MySQL account, specify a password for the anonymous account or delete the anonymous account.

Source: Internet
Author: User
Tags account security

For initial MySQL account security, you can use set password or UPDATE to specify a PASSWORD for an anonymous account or delete an anonymous account. In either case, you must use the PASSWORD () function to encrypt the PASSWORD. Use PASSWORD in Windows:

shell> mysql -u rootmysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');mysql> SET PASSWORD FOR ''@'%' = PASSWORD('newpwd');

 

To use PASSWORD in Unix:
shell> mysql -u rootmysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');mysql> SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');

 

Replace host_name in the second set password statement with the server host name. This is the Host column name of the root non-localhost record in the specified use r table. If you do not know the host name, run the following statement before set password:
mysql> SELECT Host, User FROM mysql.user;

 

Search for records with root in the User column and with no localhost in the Host column. Then use the Host value in the second set password statement. Another way to specify a password for an anonymous account is to use UPDATE to directly modify the user table. Use root to connect to the server and run the UPDATE statement to specify a value for the Password column recorded in the corresponding user table. The process is the same in Windows and Unix. The following UPDATE statement specifies a password for both anonymous accounts:
shell> mysql -u rootmysql> UPDATE mysql.user SET Password = PASSWORD('newpwd') WHERE User = '';mysql> FLUSH PRIVILEGES;

 

After updating the password directly in the user table, the server must re-read the authorization table with flush privileges. Otherwise, no changes will be used before the server is restarted. If you prefer to delete an anonymous account, follow these steps:
shell> mysql -u rootmysql> DELETE FROM mysql.user WHERE User = '';mysql> FLUSH PRIVILEGES;

 

You can use the DELETE statement in Windows and Unix. In Windows, if you only want to delete an anonymous account with the same permissions as root, the method is:
shell> mysql -u rootmysql> DELETE FROM mysql.user WHERE Host='localhost' AND User='';mysql> FLUSH PRIVILEGES;

 

This account allows anonymous access, but has all permissions, so deleting it can improve security.

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.