1 Open a console and enter
mysql -u root
The default installation has two hosts: localhost and the HOST_NAME of your installation. You can check this by entering
SELECT Host, User FROM mysql.user;
In this statement ‘mysql’ is the database and ‘user’ the table which you are accessing. To assign passwords to the root user on each host, enter
SET PASSWORD FOR ‘root’@‘localhost’ = PASSWORD(‘password’);
SET PASSWORD FOR ‘root’@‘HOST_NAME’ = PASSWORD(‘password’);
replacing ‘HOST_NAME’ with the hostname of your installation.
By using the PASSWORD( ) function, you ensure that the passwords are encrypted. From here on, whenever you wish to log on as root, log on using
mysql -u root -p
and MySQL will prompt you for your password which will not appear on the screen.
2 Removing one or both anonymous users
With the standard installation, there are normally two anonymous users; retaining these makes it easy for you, and for anyone else, to connect to your database. If you choose to retain either anonymous user, you should assign passwords to them with
SET PASSWORD FOR ’ ‘@`localhost’ = PASSWORD(‘password’);
SET PASSWORD FOR ’ '@‘HOST_NAME’ = PASSWORD(‘password’);
replacing ‘HOST_NAME’ with the hostname of your installation. Otherwise you should delete the anonymous user from localhost and you may wish to delete both anonymous users before proceeding further. To delete the anonymous user from localhost enter
DELETE FROM mysql.user WHERE Host = ‘localhost’ AND User = ’ ';
FLUSH PRIVILEGES;
To delete both anonymous users enter
DELETE FROM mysql.user WHERE User = ’ ';
FLUSH PRIVILEGES;
FLUSH PRIVILEGES ensures that the changes take effect immediately and not when Linux is rebooted which could be a very long time in some cases, leaving the anonymous users open for anyone to use.
Sorry is some of this is too basic but I thought it best to put it all in.