LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-05-2010, 06:11 AM   #1
renzorizzato
LQ Newbie
 
Registered: Jun 2008
Posts: 2

Rep: Reputation: 0
Mysql connection problem


I'm tryng to write a simple program c++ to connect to Mysql database based in my 127.0.0.1 server:

int main (void) {
cout << "\033[2J" << "\033[0;0f";

MYSQL mysql;
MYSQL *conn;

conn = mysql_init(&mysql);
cout << "conn = " << conn << "\n";
// cout << "mysql = " << &mysql;
int mysql_ping(MYSQL *mysql);

if (!mysql_real_connect(conn, host, db_user, db_pass, database, 0, NULL, 0))
{
fprintf(stderr, "Errore di connessione al database: Error: %s\n", mysql_error(conn));
}

cout << "\nConnessione avvenuta\n";
cout << "host: " << host << "\n";
cout << "passw: " << db_pass << "\n";

res = mysql_use_result(conn);

/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
{
printf("%s \n", row[0]);
cout << row[0];
}

mysql_close(conn); // chiude la connessione

cout << "\nConnessione chiusa\n";
return 0;
}

All I get in the terminal is:

conn = 0xbfcf4038
Errore di connessione al database: Error: Can't connect to MySQL server on '127.1.0.1' (111)

Connessione avvenuta
host: 127.1.0.1
passw: gina
MySQL Tables in mysql database:
Segmentation fault
renzo01@renzo01-laptop:~/software/cpp/2010$

Any suggestion?

Thank you in advance!
 
Old 09-05-2010, 11:13 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,822

Rep: Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610
you marked the thread solved, how did you solve this?
 
Old 09-07-2010, 03:32 PM   #3
renzorizzato
LQ Newbie
 
Registered: Jun 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Idiot twice
Wrong answer in the wrong place, anyway, I wrote the wrong IP into the code: 127.1.0.1 instead of 127.0.0.1 :
using namespace std;

MYSQL_RES *res;
MYSQL_ROW row;

const char *host = "127.0.0.1";
const char *database = "matrici";
const char *db_user = "renzo01";
const char *db_pass = "gina";

int main (void) {
cout << "\033[2J" << "\033[0;0f";

MYSQL mysql;
MYSQL *conn;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql connection problem cmontr Programming 3 09-08-2009 05:35 PM
MySQL connection problem wendle Linux - Newbie 11 09-30-2008 02:36 AM
MySQL Connection Problem rowancompsciguy Linux - Software 2 09-21-2006 01:53 AM
mysql connection problem I_AM Linux - General 2 10-27-2005 10:02 PM
mysql connection problem ckamheng Linux - Software 1 05-31-2003 01:30 AM


All times are GMT -5. The time now is 02:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration