Jump to content
  • Advertisement
Sign in to follow this  
Ripiz

[C++] MySQL fails to connect

This topic is 3074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My code:
#include "MySQL\mysql.h"
#pragma comment( lib, "MySQL/libmysql.lib" )

int main(void){
MYSQL *sql = new MYSQL(), *connection = 0;
mysql_init(sql);
connection = mysql_real_connect(sql, "localhost", "root", "mypass", "mydb", 0, 0, 0);
if (connection == NULL) {
printf(mysql_error(sql));
printf("\n");
system("pause");
return 0;
}
return 0;
}



It outputs this:
Can't connect to MySQL server on 'localhost' (10061)


However if I use
mysql -uroot -pmypass
in command line, it connect successfully.

Anyone know what's the problem? ^^

[Edited by - Ripiz on July 12, 2010 1:52:57 AM]

Share this post


Link to post
Share on other sites
Advertisement
Maybe try NULL or 127.0.0.1 instead of localhost, and check that your firewall is not blocking your program.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!