Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 user in MySQL, hosts = "%" and '" (empty)

Tags:

mysql

What distinguishes a user in MySQL?

1st user:

CREATE USER 'user5'@'';
SET PASSWORD FOR 'user5'@'' = PASSWORD('123457');

2nd user:

CREATE USER 'user5'@'%';
SET PASSWORD FOR 'user5'@'%' = PASSWORD('123456');
like image 874
Devid G Avatar asked Jan 28 '11 16:01

Devid G


People also ask

How do I delete multiple users in MySQL?

You can use the DROP USER statement to drop multiple users by comma separating the users that you wish to drop. For example: DROP USER 'smithj'@'localhost', 'andersonk'@'localhost'; This DROP USER example would drop two users in MySQL - smithj and andersonk.

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).

How do I use another user in MySQL?

If you want to login as a different user on MySQL, you need to use “mysql -u -p command”.


2 Answers

The part after @ specifies a host from which the user being created is allowed to connect. For example, for web applications where Web-server and MySQL server live on the same physical machine, this parameter usually set to localhost. % means all hosts, saying that user is allowed to connect from any machine.

Although username@hostname1 and username@hostname2 use same username, they are different users and can have different privileges.

like image 101
galymzhan Avatar answered Sep 26 '22 23:09

galymzhan


'user5'@'' and 'user5'@'%' is the same. but the user with the host =% has a higher priority to the user with a host =''.

like image 26
Ssoon Avatar answered Sep 23 '22 23:09

Ssoon