Connection Timeout on Openshift MySQL Cartgridge - php

I'm deploying a PHP app which uses Doctrine as ORM in Openshift. In my post_deploy action hook I run doctrine orm schema-tool to update the DB but I'm getting a Connection Timeout error.
As I'm farily new to Openshift, what is the best way to setup the database on Openshift?
UPDATE
I have two gears, one for the app and other for MySQL. I ssh into the app gear and ran
doctrine orm:schema-tool:update
Which results in a Connection Timeout error.
If I try
mysql -h $OPENSHIFT_MYSQL_DB_HOST
-p $OPENSHIFT_MYSQL_DB_PORT
-u $OPENSHIFT_MYSQL_DB_USERNAME
-P $OPENSHIFT_MYSQL_DB_PASSWORD
-
I get a prompt and the subsequent error after entering the MySQL password informed by Openshift.
Enter password:
ERROR 1049 (42000): Unknown database '<obsfucated_password>'
UDPATE 2:
As an unrelated thing pointed by Martin below, the mysql syntax is wrong. After fixing it I found that
mysql -u $OPENSHIFT_MYSQL_DB_USERNAME
-h $OPENSHIFT_MYSQL_DB_HOST
-P $OPENSHIFT_MYSQL_DB_PORT
-D $OPENSHIFT_APP_NAME
-p $OPENSHIFT_MYSQL_DB_PASSWORD
Results in
Enter password:
ERROR 1045 (28000): Access denied for user 'adminjbEnwMq'#'10.63.71.68' (using password: NO)
While runnning
mysql -u $OPENSHIFT_MYSQL_DB_USERNAME
-h $OPENSHIFT_MYSQL_DB_HOST
-P $OPENSHIFT_MYSQL_DB_PORT
-D $OPENSHIFT_APP_NAME
Connects successfully.
UPDATE 3
On the PHP side I'm running the following test code, thanks to this answer:
<?php
require_once "vendor/autoload.php";
require_once "vendor/doctrine/common/lib/Doctrine/Common/ClassLoader.php";
use Doctrine\DBAL\Configuration;
$config = new \Doctrine\DBAL\Configuration();
define('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST'));
define('DB_PORT',getenv('OPENSHIFT_MYSQL_DB_PORT'));
define('DB_USER',getenv('OPENSHIFT_MYSQL_DB_USERNAME'));
define('DB_PASS',getenv('OPENSHIFT_MYSQL_DB_PASSWORD'));
define('DB_NAME',getenv('OPENSHIFT_GEAR_NAME'));
$connectionParams = array(
'dbname' => DB_NAME,
'user' => DB_USER,
'password' => DB_PASS,
'host' => DB_HOST,
'driver' => 'pdo_mysql',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
var_dump($conn);
echo $conn->query("SHOW TABLES");
?>
And I get the same timeout error.

I cannot help you with your doctrine question, but the mysql command syntax is actually wrong.
Usage: mysql [OPTIONS] [database]
As you can see in your output, mysql is interpreting your password as the database name.
If you want to specify the optionas as you showed above you need to add an '=' between the option and the option-value.
mysql --host=$OPENSHIFT_MYSQL_DB_HOST
--port=$OPENSHIFT_MYSQL_DB_PORT
--user=$OPENSHIFT_MYSQL_DB_USERNAME
--password=$OPENSHIFT_MYSQL_DB_PASSWORD
If you want to add the database name to your command, the default database name is $OPENSHIFT_APP_NAME. Just add it at the end of your mysql command.
To see all the mysql options do mysql --help

Maybe it was because I was always working on this after 23hs, but this morning I realized I was not setting the port connection parameter. The following code works like a charm:
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => getenv('OPENSHIFT_MYSQL_DB_HOST')?: '127.0.0.1',
'port' => getenv('OPENSHIFT_MYSQL_DB_PORT')?:'3306',
'user' => getenv('OPENSHIFT_MYSQL_DB_USERNAME')?: 'stpe',
'password' => getenv('OPENSHIFT_MYSQL_DB_PASSWORD')?: 'thefallen1',
'dbname' => getenv('OPENSHIFT_APP_NAME')?:'stpe',
);

Related

Access denied for 'user'#'localhost'

I'm trying to create model using phalcon. But when I type phalcon model polls I get an error as ERROR: SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES).
I can get into mysql using mysql -p. So I tried to create new user and grant him all privileges, but it didn't help. I also can login into phpmyadmin using root and password. I also tried to specify the port as 3306 in config file, but still nothing.
My config file:
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');
return new \Phalcon\Config([
'database' => [
'adapter' => 'Mysql',
'host' => 'localhost',
'port' => 3306,
'username' => 'root',
'password' => '$Pass1234 ',
'dbname' => 'poll_db',
'charset' => 'utf8',
],
'application' => [
'appDir' => APP_PATH . '/',
'controllersDir' => APP_PATH . '/controllers/',
'modelsDir' => APP_PATH . '/models/',
'migrationsDir' => APP_PATH . '/migrations/',
'viewsDir' => APP_PATH . '/views/',
'pluginsDir' => APP_PATH . '/plugins/',
'libraryDir' => APP_PATH . '/library/',
'cacheDir' => BASE_PATH . '/cache/',
// This allows the baseUri to be understand project paths that are not in the root directory
// of the webpspace. This will break if the public/index.php entry point is moved or
// possibly if the web server rewrite rules are changed. This can also be set to a static path.
'baseUri' => preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"]),
]
]);
P.S I did all operation about granting privileges entering to mysql by mysql -u root -p
P.P.S I also did FLUSH PRIVILEGES and then restarted mysql, but nothing. Thanks for future help.
UPD: I also tried to created project in laravel, and made migration and everything works fine. I also used root + password.
SOLVED: I don't know why, but I decided to create new project, and everything worked fine even with 'root'#'localhost'. Seems like something wrong was with first project. Even so, thank for all people who participated in helping.
P.S I marked EternHour's answer as solution just for people who might get same error in future.
I don't think this is a port issue, the request is reaching it's destination. Using root#localhost will work when logging in through the command line (mysql -u root -p) but you don't want to use it for connecting with your code. Keep in mind that when establishing your connection, you need to use host=localhost or host=127.0.0.1 explicitly. If you use the IP address (even on the same server), you will get access denied.
[user#localhost ~]# mysql --host=127.0.0.1 --protocol=TCP -u root -p
Enter password:
mysql>
[user#localhost ~]# mysql --host=192.168.1.10 --protocol=TCP -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'hostname' (using password: YES)
Here are the steps I'd recommend taking:
Create a dedicated user that you can use for connecting in your scripts.
If source of script is same server as MySQL.
CREATE USER '<user>'#'localhost'
IDENTIFIED BY 'password';
GRANT ALL
ON <database>.*
TO '<user>'#'localhost';
If the connection is always established from the same place but a different location than MySQL, run the following on the command line.
CREATE USER '<user>'#'<IP_address>'
IDENTIFIED BY 'password';
GRANT ALL
ON <database>.*
TO '<user>'#'<IP_address>';
If the source of the connection varies, run the following command.
CREATE USER '<user>'#'<IP_address>'
IDENTIFIED BY 'password';
GRANT ALL
ON <database>.*
TO '<user>'#'%';
Here is a link to the documentation if you have any questions.

drush si failure user has access, Failed to create database: ERROR 1045 (28000): Access denied for user

I am running the following sets of commands to automatically install a certain drupal website
phpMyAdmin, has a database named x_init_testing, and has a user testing with password secret that can log into it (a manual drupal install is working fine, and there is an access to the db with the user and the password)
First, I am running
mysqladmin -utesting -psecret drop x_init_testing -f
mysqladmin -utesting -psecret create x_init_testing
both of these work fine, and clear the database (which should allow drush to install a new site on it)
then I am running
drush si profileName --db-url=mysql://root#127.0.0.1/x_init_testing -y --account-pass=secret
root has a password (i.e., it is not empty)
and drush sql connect does work
drush sql-connect
mysql --user=testing --password=secret --database=x_init_testing --host=127.0.0.1 --port=8889
the site is stored on MAMP (i.e., locally on my machine so no network problems)
and my settings.php file is configured with the db
*/
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'x_init_testing',
'username' => 'testing',
'password' => 'secret',
'host' => '127.0.0.1',
'port' => '8889',
'driver' => 'mysql',
'prefix' => '',
),
),
);
Still running the drush si results in
You are about to CREATE the 'x_init_testing' database. Do you want to continue? (y/n): y
Failed to create database: ERROR 1045 (28000): Access denied for user[error]
'root'#'localhost' (using password: NO)
If needed I am using: Drush Version 8.1.6, and it seems that I am using all the required arguments for the si
I think I found the issue, in theory the root user starts with no password, and this is why the command worked on machines that did not set a root password
changing the si command to :
drush si profileName --db-url=mysql://root:password#127.0.0.1/x_init_testing -y --account-pass=secret

Can't connect to MySQL through MAMP

So here's my array containing my credentials.
'mysql' => array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '*',
'db' => 's'
)
And the actual connection
try{
$this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'),Config::get('mysql/username'),Config::get('mysql/username'));
}
catch(PDOException $e){
die($e->getMessage());
}
And this is the error I get
SQLSTATE[28000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
But I am aware that this means access is denied, but the credentials are 100% correct. I also tested via command line and through workbench.
Are you sure a password is set? What happens if you attempt to connect via the command line line this:
/Applications/MAMP/Library/bin/mysql -uroot
Also, the password for root in MAMP is root. This is no deep/dark secret. Is the * in your example valid?
And in your connector, have you tried using localhost instead of 127.0.0.1? I have seen some MySQL setups work with one but not the other when it should be both.
EDIT: If you somehow mucked up the root password, don’t panic! You can still reset it this way. Warning, some folks feel this method of password reset is “risky” but that is generally true for a production server or any server in the wild. From MAMP on your desktop, this should be 100% safe.
First, stop MAMP entirely.
Next, start it up again from the command line with the skip-grant-tables option like so:
/Applications/MAMP/Library/bin/mysqld --skip-grant-tables
Once that is done, you can login with 100% no password just like this:
/Applications/MAMP/Library/bin/mysql -uroot
Then you can reset the root password with this one-liner:
UPDATE user SET Password=PASSWORD('root') WHERE user='root'; FLUSH PRIVILEGES; exit;
Okay, now find the process running the MySQL daemon with skip-grant-tables from the command line like this:
ps -u [your system username] | grep "mysqld --skip-grant-tables"
A list with two items should be returned: One is the mysqld & the other is the command you just made. Something like this:
502 1759 ttys004 0:00.11 /Applications/MAMP/Library/bin/mysqld --skip-grant-tables
502 1766 ttys004 0:00.00 grep mysqld
Okay, so now we know the mysqld with skip-grant-tables has process ID 1759, go ahead and kill that like so:
kill 1759
Restart MAMP again & the root password should work as expected now.
Try adding a port to your array! For me, it worked! The port is 8889 by default. You can change it by going to MAMP>Preferences, then the Ports tab. Here's what I think (I haven't tried this!):
'mysql' => array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '*',
'port' => '8889',
'db' => 's'
)
You use Config::get('mysql/username') twice, the second should be Config::get('mysql/password')

Connect Laravel on ubuntu to Azure SQL Server

I am developing an laravel app using ubuntu as OS and my database is in a remote Azure Server.
After long a research I'm about to give up. Installed freetds, php5-sybase etc etc.
here is my connection file: (the default is set to sqlsrv)
....
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'myhostname:myport',
'database' => 'mydatabasename',
'username' => 'myusername',
'password' => 'mypassword'
),
....
and the error that I am getting is this one:
PDOException
SQLSTATE[01002] Adaptive Server connection failed (severity 9)
Any sugestions? If you guys need more details please ask :)
Thanks in advance
I solved my problem. It was missing #domain in my query string example:
$pdo = new PDO("dblib:host=xxxx:1433;dbname=yyyy", 'username#domain', 'password');
I get solution in Read from the server failed when trying to connect to sql-azure from tsql
Edit /etc/freetds/freetds.conf file and use 8.0 TDS version.
If haven't this file install FreeTDS with
sudo apt-get install freetds-bin
Check these:
port separator is "," on windows and ":" on linux/Mac. Since you have 1433, the default one, it is better probably not to use it at all
definitely test first from command line using one of these :
$ tsql -S sectionNameInFreetdsconf -U user -P pass
$ tsql -H hostname -p port -U user -P pass
locate freetds.conf on your disk. It is possible it exists in several places and tsql uses one while PHP used another one. Best is to symlink them into one common file and test on that. Note that a common place for that file is ~/.freetds.conf beside /etc/ or /usr/local/etc/
there should be a [global] section on your freetds.conf file. Put there these lines :
tds version = 8.0
text size = 20971520
client charset = UTF-8

Cannot connect to PgSQL via Laravel SQLSTATE[08006] [7] FATAL

I'm trying to connect to pgsql via laravel and finally got everything setup (pgsql server running, pdo installed, all libs installed). I'm running on a VPS (CentOS) managed via CPanel/WHM.
Here's what I'm doing:
I'm trying to create a user database via artisan (Laravel's command line) using migrate:install.
For those that don't use Laravel, artisan uses php's PDO for pgsql to connect. Here are my settings:
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'prefix' => '',
),
I've also setup a test.php file:
$dbconn = pg_connect("host=localhost port=5432 dbname=dbname user=username password=password");
which also fails. I used phpPgAdmin to see what's up and all of the permissions are set correctly, the database shows up, the username is correct, same with password. I checked where postgre (version 8.4.12 btw) was running and phpPgAdmin tells me "localhost:5432".
The error I get via the command line is the following:
SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host "::1", user "myusername", database "my_database", SSL OFF
Now, I tried to find the pg_hba.conf file but I'm not entirely sure where to look for it. Same goes for the error/access logs for pg and google hasn't been any help as far as this goes.
Any idea on what I can do?
localhost points to IPV6 ::1 address on your system. Postgresql makes the difference between ipv6 and ipv4 addresses when dealing with access list.
I was able to install/configure everything correctly. I changed the "host" to 127.0.0.1, not sure why that made a difference but it did :)

Categories