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