Can't connect to local MySQL through socket

Just starting out? Need help? Post your questions and find answers here.
User avatar
RBart
User
User
Posts: 35
Joined: Sun May 04, 2025 11:18 am

Can't connect to local MySQL through socket

Post by RBart »

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'opencart_db');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');

According to the documentation of PureBasic this would work:

Hi
I have a Xampp server running locally. With MariaDB. On Linux Ubuntu lts 22.04
The server has a working connection with an Opencart that's also locally, this works fine.
The config of this connection that works for OpenCart:

Code: Select all

UseMySQLDatabase()

  ; You should have a server running on localhost
  ;
  If OpenDatabase(0, "host=localhost port=3306 dbname='opencart_db'", "root", "")
    Debug "Connected to MySQL"
  Else
    Debug "Connection failed: "+DatabaseError()
  EndIf
I'm sorry,
I got the following error: Connection failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Seems like PureBasic searching the connection on a socket that isn't the right one.

rudi@Slimbook:~$ ls -l /opt/lampp/var/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 jan 7 08:51 /opt/lampp/var/mysql/mysql.sock
rudi@Slimbook:~$ ls -l /tmp/mysql.sock
ls: kan geen toegang krijgen tot '/tmp/mysql.sock': Bestand of map bestaat niet (translation: can't connect... file or folder doesn't exist)
rudi@Slimbook:~$

Solved it by creating a sym link

ln -s /opt/lampp/var/mysql/mysql.sock /tmp/mysql.sock

Greetings from Belgium

Rudi
💻 Exploring the world of PureBasic