Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using % for host when creating a MySQL user

Tags:

mysql

My MySQL database needs two users: appuser and support.
One of the application developers insists that I create four accounts for these users:

appuser@'%' appuser@'localhost' support@'%' support@'localhost' 

For the life of me I can't figure out why he thinks we need this. Wouldn't using the wildcard as the host take care of the 'localhost'?

Any ideas?

(Using MySQL 5.5 here)

like image 608
Ed Manet Avatar asked May 30 '12 20:05

Ed Manet


People also ask

What is host in MySQL user?

The MySQL hostname defines the location of your MySQL server and database. If you want to connect to the information in a MySQL database, you'll need to know the hostname. Again, the hostname is usually localhost, which indicates that the database is running on the same server as your application (e.g. WordPress).

What should be the host name in MySQL?

The MySQL hostname will always be 'localhost' in your configuration files.

What does @% mean for host in MySQL?

'%' mean you can login into database from any host connected to those database. You also define your localhost as host if you want to access database from localhost. to change your password: SET PASSWORD FOR 'me'@'%' = PASSWORD('letmein');


1 Answers

localhost is special in MySQL, it means a connection over a UNIX socket (or named pipes on Windows, I believe) as opposed to a TCP/IP socket. Using % as the host does not include localhost, hence the need to explicitly specify it.

like image 145
aleroot Avatar answered Oct 19 '22 20:10

aleroot