Overview
Features
Download
Documentation
Community
Add-Ons & Services

MySQL - Connection attempt failed

Please post support and help requests here.

MySQL - Connection attempt failed

Postby flomll » 21 Nov 2012, 15:30

Hy, have anyone an idea what's the problem?

Connection attempt failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Code: Select all
   try {
      // Exception thrown at this line:
      _pSession = new Session(Connector::KEY, "user=pma;password=1209gT;db=devicesharing_db1;compress=false;auto-reconnect=true");

      string name;

      // a simple query
      Statement select(*_pSession);
      select << "SELECT name FROM `j4s92_users`", into(name), range(0,1), now;
      select.execute();

      cout << "Name: " << name;
   } catch(Poco::Exception& e)
   {
      std::cerr << e.displayText();
   }


I run the Connector::registerConnector(); and Connector::unregisterConnector(); at the CTor and DTor of the class. The exception message I got at the marked line.
flomll
 
Posts: 28
Joined: 18 May 2012, 08:58
Location: Austria

Re: MySQL - Connection attempt failed

Postby flomll » 21 Nov 2012, 15:47

New error:

Connection attempt failed: Access denied for user 'pma'@'localhost' (using password: YES)

Code: Select all
..
std::string NSDBWatcher::_dbConnString = "host=" MYSQL_HOST
   ";user=" MYSQL_USER
   ";password=" MYSQL_PWD
   ";db=" MYSQL_DB
   ";compress=true;auto-reconnect=true";
..

   try
   {
      Poco::Data::MySQL::Connector::registerConnector();
      _pSession = new Session(Connector::KEY, _dbConnString);

      string name;

      // a simple query
      Statement select(*_pSession);
      select << "SELECT name FROM `j4s92_users`", into(name), range(0,1), now;
      select.execute();

      cout << "Name: " << name;
   } catch(Poco::Exception& e)
   {
      std::cerr << e.displayText();
   }
   Poco::Data::MySQL::Connector::unregisterConnector();



For the host I use now 127.0.0.1 instead of localhost like a sample of MySQL TestSuite.
flomll
 
Posts: 28
Joined: 18 May 2012, 08:58
Location: Austria

Re: MySQL - Connection attempt failed

Postby alex » 22 Nov 2012, 20:38

Try running it from another machine. If it connects, you have a problem with MySQL configuration not allowing connections from local machine. I have encountered this and, although I can't recall details, I'm sure google will know.
alex
 
Posts: 1048
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: MySQL - Connection attempt failed

Postby flomll » 19 Dec 2012, 14:19

The problem is fixed if I run mysql like

Code: Select all
sudo /opt/lampp/sbin/mysqld --skip-grant-tables
flomll
 
Posts: 28
Joined: 18 May 2012, 08:58
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests