Jump to content
  • Advertisement
Sign in to follow this  
Ripiz

[C++] MySQL fails to connect

This topic is 2996 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!