I created a test user for my database. It is MySQL/MariaDB (running the MySQL server that comes with XAMPP).
Steps to create the test user:
CREATE USER 'user1'@'%' IDENTIFIED BY 'user1';
GRANT ALL PRIVILEGES ON mydb.* TO 'user1'@'%' IDENTIFIED BY 'user1';
FLUSH PRIVILEGES;
Next, I tried to log in with a C# WinForms application as that user.
Since I am on my local machine, I just used 127.0.0.1
as the host.
Connection string was: Server=127.0.0.1; Port=3306; Database=mydb; Uid=user1; Pwd=user1;
I got the following error message upon trying to open the connection:
Authentication to host '127.0.0.1' for user 'user1' using method 'mysql_native_password' failed with message: Access denied for user 'user1'@'localhost' (using password: YES)
Upon doing a SELECT host, user, password FROM mysql.user
I get the following:
+-----------+-------+-------------------------------------------+
| host | user | password |
+-----------+-------+-------------------------------------------+
| localhost | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| localhost | pma | |
| % | user1 | *B9CFB5C1F2F7B45EF0F9A826B2250F6250D85E73 |
+-----------+-------+-------------------------------------------+
So, why am I seeing this error message? Since the domain for user1
is defined as any (%
), I should be able to connect with this user from localhost
or 127.0.0.1
, no?