Users and Hosts

So far, we’ve discussed the steps to grant privileges, as well as how these privileges interact in a hierarchy. However, we’ve skipped over the basic principles of connecting to the server and explaining how MySQL validates a connection. This section covers these topics and helps you understand how you connect to a MySQL server.

Local and Remote Users

MySQL supports both local and remote users. A local user connects to the server and accesses the databases from the same computer that the MySQL server is running on (localhost). All our examples so far have been for a local user. In contrast, a remote user connects to the server and accesses the databases from another computer.

For each application, you must decide how the database will be used and apply the most restrictive set of access privileges needed to get the job done. There are performance as well as security issues to be considered when doing this. MySQL actually treats local connections differently; if the client is local, the connection is made internally through a Unix socket (for Linux and Mac OS X) or through a named pipe (for Windows). This is generally much faster than the TCP/IP network connection used for remote access.

You should be careful not to give remote access to the database when you can avoid it. Consider the case where three different managers need to see how many items of each title there are in stock. You could give each manager an account on the MySQL server and allow remote access so that ...

Get Learning MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.