Initialize Mysql user (delete anonymous user) _mysql

Source: Internet
Author: User
Tags anonymous

When MySQL is installed, the system defaults to creating a root user that does not require a password, and an anonymous user (Anonymous account) without a username and no password. Perform the following initialization actions to enhance security with reasonable authorization.

Set root password first log in mysql-u root as root, set root password:

SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' New_password ');
Create a new user # Create a user and set a password
CREATE user ' new user ' @ ' localhost ' identified by ' new password ';
# Authorization to the user
Grant all privileges in *.* to ' new user ' @ ' localhost ' with GRANT OPTION;
Delete anonymous user drop user ' @ ' localhost ';

If you are prompted for an error, such as:

Copy Code code as follows:

mysql< DROP USER ' @ ' localhost ';
ERROR 1396 (HY000): Operation DROP USER failed for ' @ ' localhost '

It is because the *nix system needs to be deleted in the way of ' user ' @ ' hostname '. The method is as follows:

Copy Code code as follows:

# Find the exact hostname first
Select User,host from Mysql.user;
# Find the host name where user is empty
# Delete this anonymous user
DROP USER ' @ ' hostname found in the previous step ';

Via

Set Password: https://dev.mysql.com/doc/refman/5.1/en/assigning-passwords.html
Create User: Https://dev.mysql.com/doc/refman/5.1/en/adding-users.html

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.