I am attempting to connect to a MySQL database setup by XAMPP using the MySQL Connector C API on OSX. Using this code:
MYSQL mysql;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0))
{
printf("Failed to connect to database: Error (%d): %s",mysql_errno(&mysql),mysql_error(&mysql));
}
else printf("Connection success!");
I get the following result:
Failed to connect to database: Error (2002): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I can confirm the database is operational because phpMyAdmin connects to it fine, here is the config.inc.php file:
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true;
Does anyone know why phpMyAdmin can connect but my C program cannot? I have tried forcing TCP/IP connections to no avail.