Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Users 'User'@'%' and 'User'@'localhost' not the same?

Tags:

mysql

I created a user per the first command but cannot logon via localhost (linux). This link mysqldoc indicates that I need to create a second user by the same name, but using the syntax in the second block of commands.

mysql> CREATE USER 'myuser'@'%' IDENTIFIED BY '4myuser'; Query OK, 0 rows affected (0.00 sec)  mysql> GRANT ALL ON my_upload.* TO 'myuser'@'%' IDENTIFIED BY '4myuser'; Query OK, 0 rows affected (0.00 sec) 

So I tried that as below, and it indeed worked. But are these two separate users? If I change the pw for one, will the other one sync, or are they truly separate users?

mysql> CREATE USER 'myuser'@'localhost' IDENTIFIED BY '4myuser'; Query OK, 0 rows affected (0.00 sec)  mysql> GRANT ALL PRIVILEGES ON my_upload.* TO  'myuser'@'localhost'; Query OK, 0 rows affected (0.00 sec) 
like image 485
EdgeCase Avatar asked Jul 24 '12 15:07

EdgeCase


People also ask

What is the difference between localhost and in MySQL?

Your answer The difference is that when you use localhost, the socket connector is used. Whereas, when you use 127.0. 0.1, TCP/IP connector is used.

What does host mean 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 does '%' as database host mean?

'%' 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.


2 Answers

User@% would allow access from all locations. User@localhost would only allow access from localhost. They are two different users with two different passwords (though you can set them to the same password, but if you update one password the other will not auto-update)

like image 187
Mike Brant Avatar answered Oct 03 '22 08:10

Mike Brant


Basically yes, those are two different users with (possibly) different permissions and (possibly) different passwords.

  • myuser@% : User myuser, connecting from any host.
  • myuser@localhost : User myuser, connecting from localhost only.

A good read is the MySQL manual about connection access, it demonstrates how it works.

like image 39
Bjoern Avatar answered Oct 03 '22 09:10

Bjoern