MySQL – Handling Multiple ‘root’ Users

MySQL

Mysql is showing 5 root users:

| root   | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
| root   | localhost |
| root   | mysrverhostname |

What are these 5 for? Are there some I can delete?

Best Answer

| root | % | - This is the root user from any computer
| root | 127.0.0.1 | - This is the root user for localhost without resolved IP for IPv4
| root | ::1 | - This is the root user for localhost without resolved IP for IPv6
| root | localhost | - This is the root user for localhost with resolved IP
| root | mysrverhostname | - This is the root user if you connect from the localhost to its externel IP.

You could the delete the first one if you don't like to connect from another computer to this server as root.

All other root users are useful, because you can do the follow types of mysql connections:

  • mysql -h 127.0.0.1 -u root (IPv4)
  • mysql -h ::1 -u root (IPv6)
  • mysql -h localhost (If the mysql server is configured to resolve IPs, the the 2 above would get used)
  • mysql -h 192.168.0.1 -u root (the IP of the server)
  • mysql -h mysqlserver.local -u root (the hostname of the server)

and if I remember correctly the "localhost" user get used if you connect using a socket connection.