Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 09-05-2010, 07:11 AM   #1
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 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 '' (111)

Connessione avvenuta
passw: gina
MySQL Tables in mysql database:
Segmentation fault

Any suggestion?

Thank you in advance!
Old 09-06-2010, 12:13 AM   #2
Senior Member
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614
you marked the thread solved, how did you solve this?
Old 09-07-2010, 04:32 PM   #3
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: instead of :
using namespace std;


const char *host = "";
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;


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 06:35 PM
MySQL connection problem wendle Linux - Newbie 11 09-30-2008 03:36 AM
MySQL Connection Problem rowancompsciguy Linux - Software 2 09-21-2006 02:53 AM
mysql connection problem I_AM Linux - General 2 10-27-2005 11:02 PM
mysql connection problem ckamheng Linux - Software 1 05-31-2003 02:30 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:18 PM.

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