The Wiki page SWI-Prolog connecting to PostgreSQL via ODBC might be of help. While it is not specific to your setup it does take smaller steps in verifying things along the way. Also it uses /etc/odbc.ini as opposed to .odbc.ini.
HTH
EDIT
In trying to identify where in the source code the error is being thrown found
Now knowing the database is MySQL and the error number seems to be 1045 with a Google search found many pages like this
I can login into the database with mysql -uroot -ppassword, which seems MySql database allows to login via localhost. But I still cannot connect via swiprolog
On Ubuntu, I have my DSNs defined in /etc/odbc.ini
[blog]
Driver = MySQL
Description = test ODBC
DATABASE = blog
USER = ********
PASSWORD = *********
PORT = 3306
SOCKET = /var/run/mysqld/mysqld.sock
SERVER = localhost
...
?- odbc_connect(blog,C,[]).
C = '$odbc_connection'(36329168).
It’s very strange. Today I make a new DSN which use MySQL ODBC 8.0 ANSI Driver instead of the MySQL ODBC 8.0 Unicode Driver. Now the ~/.odbc.ini file contains two DSNs.
➜ unixODBC-2.3.9 cat ~/.odbc.ini
[ODBC Data Sources]
test = MySQL ODBC 8.0 Unicode Driver
test2 = MySQL ODBC 8.0 ANSI Driver
[ODBC]
TraceLibrary =
[test]
Driver = /Library/ODBC/libmyodbc8w.so
SERVER = localhost
PORT = 3306
DATABASE = ftta-projects
USER = root
PASSWORD = *******
[test2]
Driver = /Library/ODBC/libmyodbc8a.so
SERVER = localhost
PORT = 3306
USER = root
PASSWORD = *******
DATABASE = ftta-projects
Then I call odbc_connect with the two DSNs. odbc_connect(test, C, []). reports the following error:
ERROR: ODBC: State H: [unixODBC][
ERROR: In:
ERROR: [10] odbc:odbc_connect(test,_5560,[])
ERROR: [9] toplevel_call(user:user: ...) at /usr/local/lib/swipl/boot/toplevel.pl:1162
And odbc_connect(test2, C, []). returned successfully.
?- odbc_connect(test2, C, []).
C = '$odbc_connection'(105553150193936).
So what is the difference between MySQL ODBC 8.0 Unicode Driver and MySQL ODBC 8.0 ANSI Driver? Why MySQL ODBC 8.0 Unicode Driver cannot be used in my projects?
Who knows? It has been suggested here before: first try using the commandline tools that come with the ODBC implementation. Also note that the SWI-Prolog ODBC driver can be compiled against iODBC and UnixODBC. The pre-build binary you can download from SWI-Prolog.org has been compiled against UnixODBC. The commandline tool of UnixODBC is isql as mentioned here before. iusql is its Unicode cousin. These tools have debug options that may hint at what is wrong.
The point some us are trying to make is that if you get an error from either or both isql or iusql then the problem is not with SWI-Prolog it is with something else.
Since the problem is not with SWI-Prolog you are more likely to get better help some where else.