"Access denied for user" Error Message When Connecting with C / mysqlclient library
Posted by: Peter Hummon
Date: November 16, 2018 02:18PM

Hi everyone,

I am writing my first C program that connects to a working MySQL server. The code uses the mysqlclient library and nicely compiles. Here's an excerpt:
------------------------------------------------------------------------
int main() {
MYSQL mysql;
if(mysql_init(&mysql)==NULL) {
return 0;
}
if(mysql_real_connect(&mysql, "192.168.3.2", "DemoUser", "Password01", "testDB", 3306, NULL, 0) == NULL){
return 0;
}
}
------------------------------------------------------------------------

Note the connection details with the "mysql_real_connect()" command. I've verified the User and Password details on the server:

------------------------------------------------------------------------
mysql>
mysql> SELECT User, Host, authentication_string FROM mysql.user;
+------------------+-----------+-------------------------------------------+
| User | Host | authentication_string |
+------------------+-----------+-------------------------------------------+
| ...etc...
| DemoUser | localhost | *1234567890123456789012345678901234567890 |
+------------------+-----------+-------------------------------------------+
6 rows in set (0.00 sec)

mysql>
mysql> GRANT ALL PRIVILEGES ON testDB.* to DemoUser@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW GRANTS FOR 'DemoUser'@'localhost';
+--------------------------------------------------------------+
| Grants for DemoUser@localhost |
+--------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'DemoUser'@'localhost' |
| GRANT ALL PRIVILEGES ON `testDB`.* TO 'DemoUser'@'localhost' |
+--------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>
mysql>
mysql> ALTER USER 'DemoUser'@'localhost' IDENTIFIED BY 'Password01';
Query OK, 0 rows affected (0.00 sec)

mysql>
------------------------------------------------------------------------

So the "DemoUser" exists, has access to the "testDB" database, and has the correct password.

The good news/bad news is when I run my code from a remote host, I see this in the error log:

------------------------------------------------------------------------
root@123412341234:/etc/mysql#
root@123412341234:/etc/mysql# tail -f /var/log/mysql/error.log
...
2018-11-16T19:50:30.322170Z 20 [Note] Access denied for user 'DemoUser'@'987698769876.me_sql_net' (using password: YES)
------------------------------------------------------------------------

So my program can get to the server, but the server doesn't like the login credentials or something.

Is the problem that the "DemoUser" is listed as "DemoUser@localhost" in MySQL's user table, but the connection in initiated by "DemoUser@'987698769876.me_sql_net'" (The Ubuntu container where the C program is running is 987698769876.me_sql_net) If so, how can I compensate?

Thanks!

Options: ReplyQuote


Subject
Views
Written By
Posted
"Access denied for user" Error Message When Connecting with C / mysqlclient library
1455
November 16, 2018 02:18PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.