1

Context:

I am trying to use mySQL in my Xcode c++ project. And I have this simple program available to connect to mysql:

int main(){

if(!mysql_real_connect(&mysql, "localhost", "root", "PassWord", "DB", 0, NULL, 0)) {
    printf("connecting to Mysql error:%d from %s\n",mysql_errno(&mysql), mysql_error(&mysql));
    return -1;
}else {

    printf("Connected Mysql successful!\n");

}

mysql_close(&mysql);
return 0;

}

However, I was able to connect to MySQL. After I ran this CML in my terminal

export DYLD_LIBRARY_PATH=/usr/local/lib

the program doesn't work anymore with the error showing: (my code in Xcode is below:)

I got this Error in Xcode command:

enter image description here

I am still able to log in to mySQL in CML with mysql -u root -p

And By Showing all port variables, the port shows shows it is running on 3306

SHOW GLOBAL VARIABLES LIKE 'PORT';

So everything is still normal in Terminal.

Also I tried to unset the DYLD_LIBRARY_PATH but got no luck.

I am wondering what is the reason to cause the problem and any possible resolutions/workaround.

Josh
  • 51
  • 3
  • Maybe this answer migth help [error-2003-hy000-cant-connect-to-mysql-server-on-127-0-0-1](https://stackoverflow.com/questions/1673530/error-2003-hy000-cant-connect-to-mysql-server-on-127-0-0-1-111#16164426) – Gilberto Treviño Apr 05 '20 at 23:29
  • mysql sever would work through my terminal. But I still connect to mysql sever on local host in Xcode – Josh Apr 06 '20 at 02:06

0 Answers0