I can`t find too much documentation about connecting Drupal7 website with SQL Google database. Does anybody have experience with it? I trying to split Drupal website on VM instance and mysql database on SQL Google storage. After that, change settings.php in Drupal:
$databases['default']['default'] = array(
'database' => 'DATABASE',
'username' => 'USERNAME',
'password' => 'PASSWORD',
'host' => 'Public_IP_of_Google_SQL',
'driver' => 'mysql',
'port' => 3306 (I try 1433 also),
'prefix' => '',
);
}
On SQL instance I have enabled firewall for tcp ports:3306,1433
However, I always get error
PDOException: SQLSTATE[HY000] [2002] Connection refused in lock_may_be_available() (line 167 of /home/public_html/includes/lock.inc).
Can anybody help? What can I do on Drupal side to connect website with external database?
Related
So I have 3 docker containers, one with PHP+PhalconPHP, one with MySQL and another with the webserver. Now on my host system I can connect to the MySQL in the docker container and I can also connect with PDO using the following code
new PDO('mysql:host=mysql;port=1024;dbname=database', 'root', 'password');
But for some reason the phalcon framework is unable to connect to the MySQL database using the config.php file like so
return new \Phalcon\Config([
'database' => [
'adapter' => 'mysql',
'port' => 1024,
'host' => 'mysql',
'username' => 'root',
'password' => 'password',
'dbname' => 'database',
'charset' => 'utf8',
],
]);
In this case, for some reason I am getting a Can't connect to MySQL server on 'mysql' (111 "Connection refused) even though I am 100% sure I can actually connect (as proven before with the PDO connection). I also tried hardcoding the actual MySQL container ip address but no luck either.
Any ideas?
So it appeared to be kind of a stupid "mistake" but here's the solution.
Apparently when you use the Phalcon Developer Tools to scaffold your project, it does not initialize the database with the port configuration as it outright ignores it. You can easily fix this by going into the app/config/services.php file and changing the db service to also include the port configuration.
$connection = new $class([
'host' => $config->database->host,
'port' => $config->database->port,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
'charset' => $config->database->charset
]);
I have a scenario where for a certain reason I cannot use Google's Cloud SQL. Hence I want the application at appid.appspot.com to connect to an external DB server.
DB.php
'hostname' => '202.202.202.202',
'username' => 'user',
'password' => 'password',
'database' => 'dbname',
'dbdriver' => 'mysql',
This gives me a Server Error, however I'm able to connect to the database from mysql workbench. This application does not have a problem while connecting to Cloud SQL.
Error message:
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
Can someone help me understand where I'm going wrong.
I did the following changes and got it working.
Instead of IP address I gave the external DB server a hostname.
'hostname' => 'dbserver.example.com',
'username' => 'user',
'password' => 'password',
'database' => 'dbname',
'dbdriver' => 'mysqli',
Then I activated billing for the Google App Engine project. Once you activate billing the Google Socket API will start functioning.
Please do not try immediately. Give it sometime and this should start working just fine.
I'm getting this error when trying to connect to an SQL Server DB from Laravel 4.2.
Here's my DB config:
'connections' => array(
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'example.noip.me',
'database' => 'db',
'username' => 'sa',
'password' => 'pass',
'prefix' => '',
),
),
//...
It works perfectly in my home computer, but not in production. This project is in a hosting service, so I can't change much of the config (can still use ini_set though).
I tried adding the port to the server address but it didn't work.
Edit: I forgot to mention that the hosting and the database server are on different computers, so it could be a security configuration problem.
I contacted tech support and it turned out to be a matter of configuration in the hosting server (Remote Database Access Hosts, which I thought was for MySQL only).
Okay so i am trying to connect to my remote SQL database.
i am using the following settings:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => '10.246.16.153:3306',
'login' => '*******',
'password' => '*******',
'database' => 'udlejnings_pris',
'prefix' => '',
//'encoding' => 'utf8',
);
My Database settings are the following:
Database server
Server: 10.246.16.153 via TCP/IP
Software: MySQL
Software version: 5.1.66-0+squeeze1 - (Debian)
Protocol version: 10
Server charset: UTF-8 Unicode (utf8)
Now when im trying to access this server i get the following error:
2013-10-12 16:27:28 Error: [MissingConnectionException] Database connection "Mysql" is missing, or could not be created.
Exception Attributes: array (
'class' => 'Mysql',
'message' => 'SQLSTATE[HY000] [2002]
',
'enabled' => true,
)
So what am i doing wrong?
Many hosted MySQL instances don't allow clients to connect remotely by default. You may need to add your IP address into some form of Remote MySQL option if your database host provides it. For example, if the server with the database on it uses cPanel, there is a 'Remote MySQL' option on there which may resolve your issue. Alternatively, you could execute the 'GRANT' SQL command to allow your user account access remotely as described in this answer.
If you still have issues, a firewall may be blocking the connection locally too.
Maybe you need to enable mysql remote access on the server that you are connecting to. By default it is disabled.
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
I want to connect to an external Database on another Host (not localhost) on Drupal because i want to migrate Content with the Migrate Module.
thats in my settings.php
$databases['for_migration']['default'] = array(
'driver' => 'mysql',
'database' => 'dbname',
'username' => 'username',
'password' => 'password',
'host' => 'other-host.com',
'prefix' => '',
'port' => '',
);
And in another method im calling the database via:
$query = Database::getConnection('default', 'for_migration')
thats the error which appears:
PDOException: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'host.com' (13) in MigrateMigration->__construct() (Zeile 16 von /var/www/html/x/sites/all/modules/migrate_x/x.inc).
So if i call a database on localhost, there are no errors and all migrates perfectly. But i cant connect to a database on an external host.
That could be due to:
1) connection limitation (firewall block, for example).
2) the account you are using does not allows logins outside of "localhost". In this case, you will have to edit your account hostname mask on the 'user' table inside the 'mysql' database for '%' (which means, any address) or the machine IP address you are accessing from.
It was my fault. I have set httpd_can_network_connect on the remote server to on.
But the solution was to set it on my local machine. After that i can connect to an external Host. So it was a SELinux Problem.
Thanks to #fobia