Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: What does % stand for in host column and how to change user's password

Tags:

mysql

Well, this is what I can see:

select host, user from mysql.user;

+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | me               |
| 127.0.0.1 | root             |
| ::1       | root             |
| localhost |                  |
| localhost | debian-sys-maint |
| localhost | root             |
| ubuntu    |                  |
| ubuntu    | root             |
+-----------+------------------+

I entered as root and would like to change password for user 'me'.

SET PASSWORD FOR 'me'@'%' = PASSWORD('letmein');
Query OK, 0 rows affected (0.00 sec)

Well, no rows affected as we can see.

As for trying to access, the result is as follows:

Access denied for user 'me'@'localhost' (using password: YES)
michael@ubuntu:/var/www/cgi-bin$ 

So, it mentions localhost, not %.

Could you suggest me how to change the password for 'me' and explain what % is?

like image 430
Kifsif Avatar asked Oct 17 '12 10:10

Kifsif


People also ask

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

Where are user passwords stored in MySQL?

MySQL passwords for users are stored within MySQL itself; they are stored in the mysql. user table. The passwords are hashed by default using the PASSWORD() function.


2 Answers

'%' 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');

and don't forget execute:

FLUSH PRIVILEGES;

to commit your change. Please look at MySql Account Management.

UPDATE:

As on your user table I not found username with host = localhost you must create this user first by (here to add user):

Grant all privileges on *.* to me@'localhost' identified by 'letmein';
flush privileges;
like image 186
Habibillah Avatar answered Oct 15 '22 03:10

Habibillah


You need to set password for localhost:

SET PASSWORD FOR 'me'@'localhost' = PASSWORD('letmein');

FLUSH PRIVILEGES;

% means remote hosts can login to MySQL server from any other server whereas localhost means you can login to MySQL server only from same machine.

like image 23
Omesh Avatar answered Oct 15 '22 04:10

Omesh