2012-02-21 4 views
0

XAMPP으로 MySQL 데이터베이스 설정에 연결하려고합니다. OSX에서 MySQL Connector C API을 사용하고 있습니다. 나는 다음과 같은 결과를 얻을MySQL 커넥터 C API MySQL 서버에 연결할 수 없습니다.

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!"); 

:이 코드를 사용하여 phpMyAdmin을 여기에, 잘 그것을 연결하기 때문에 데이터베이스를 확인할 수 있습니다

Failed to connect to database: Error (2002): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 

가 작동하면 config.inc.php를 파일입니다

/* 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; 

누구나 phpMyAdmin을 연결할 수 있지만 C 프로그램으로 연결할 수없는 이유를 알고 있습니까? TCP/IP 연결을 사용하지 않으려 고 시도했습니다.

답변

1

당신은 기본 포트를 3306 mysql_real_connect() 함수 (& MySQL은 "로컬 호스트", "루트", "", NULL, 3306, NULL, 0)

를 연결하거나 사용한다고 가정합니다 (my.cnf 파일을 재구성 linux) mysql을 재시작하십시오.

[mysqld] 
socket=/tmp/mysql.sock 

[client] 
socket=/tmp/mysql.sock 
+0

고맙습니다. mySQL가 소켓을 찾는 경로를 찾은 후 MySQL이 청취하는 소켓을 XAMPP 변경합니다. – user293895

+0

제안한대로 포트 3306을 사용해 보았습니다. 작동하지 않았다. – user124384

관련 문제