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.