Connecting to mysql using Sequel on Openshift - mysql

I'm developing a site using Cloud9 with Ruby and Sinatra and I'm deploying to Openshift. I have set up cartridges for mySQL and PhpMyAdmin. The problem I'm having is connecting to the database using Sequel.
Here's what I have
DBS = Sequel.connect('mysql://OPENSHIFT_MYSQL_DB_USERNAME:OPENSHIFT_MYSQL_DB_PASSWORD#OPENSHIFT_MYSQL_DB_HOST:OPENSHIFT_MYSQL_DB_PORT')
heros = DBS[:superheros]
get '/mysql' do
"#{heros.first[:name]}"
#"mysql"
end
I've also tried
db_user = ENV['OPENSHIFT_MYSQL_DB_USERNAME']
db_pass = ENV['OPENSHIFT_MYSQL_DB_PASSWORD']
db_host = ENV['OPENSHIFT_MYSQL_DB_HOST']
db_port = ENV['OPENSHIFT_MYSQL_DB_PORT']
DBS = Sequel.connect('mysql://#{db_user}:#{db_pass}##{db_host}/#{db_port}')
All I'm getting back is Internal Server Error
Can anyone please provide me with some tips on how I can connect?
Thanks

DBS = Sequel.connect('mysql://#{db_user}:#{db_pass}##{db_host}/#{db_port}')
How to connect to DB with Sequel
Port and host are separated via "/", but should be ":" (colon)
You forgot database name.
Example of correct connection string:
mysql://user:password#host:port/database
Try something like that
db_user = ENV['OPENSHIFT_MYSQL_DB_USERNAME']
db_pass = ENV['OPENSHIFT_MYSQL_DB_PASSWORD']
db_host = ENV['OPENSHIFT_MYSQL_DB_HOST']
db_port = ENV['OPENSHIFT_MYSQL_DB_PORT']
db_name = ENV['OPENSHIFT_APP_NAME']
DBS = Sequel.connect('mysql://#{db_user}:#{db_pass}##{db_host}:#{db_port}/#{db_name}')

Thanks, I tried all sorts of permutations but in the end this worked
db_user = ENV['OPENSHIFT_MYSQL_DB_USERNAME']
db_pass = ENV['OPENSHIFT_MYSQL_DB_PASSWORD']
db_host = ENV['OPENSHIFT_MYSQL_DB_HOST']
db_port = ENV['OPENSHIFT_MYSQL_DB_PORT']
DBS = Sequel.connect(:adapter=>'mysql', :host=>db_host, :database=>"prescreen", :user=>db_user, :password=>db_pass)

Related

How to connect to AWS MySQL database from Java?

I want to connect to AWS MySQL database instance. Here is my code:
val hikari = HikariConfig().run {
driverClassName = "com.mysql.jdbc.Driver"
jdbcUrl = "jdbc:mysql://${mainConfig.databaseHost}:${mainConfig.databasePort}" +
"?user=username&password=password"
username = Config.DATABASE_USER
password = Config.DATABASE_PASSWORD
isAutoCommit = false
transactionIsolation = "TRANSACTION_REPEATABLE_READ"
return HikariDataSource(this)
}
Database.connect(hikari(config))
And my mainConfig.databaseHost looks like: mydatabase.xyz.region.rds.amazonaws.com.
So, this connection is working but I can't to exec any SQL statements because:
java.sql.SQLException: No database selected
I've tried to specify database name in my jdbc url but it causes exception.
So how can I connect to specified AWS database?
After research I found that DB identifier and DB name are different, so I specified DB name in jdbc url and now it working!

Config Error : I'm unable to connect my DB using Moodle

Error: Database connection failed
It is possible that the database is overloaded or otherwise not running properly.
The site administrator should also check that the database details have been correctly specified in config.php
Below My Config.php
unset($CFG);
global $CFG;
$CFG = new stdClass();
$CFG->dbtype = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->dbhost = '192.0.0.0';
$CFG->dbname = 'moodle';
$CFG->dbuser = 'root';
$CFG->dbpass = 'admindb#123';
$CFG->prefix = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,
'dbport' => 3306,
'dbsocket' => '',
'dbcollation' => 'utf8mb4_general_ci',
);
$CFG->wwwroot = 'http://192.0.0.0/moodle-apexon';
$CFG->dataroot = 'C://xampp//moodledata';
$CFG->admin = 'admin';
Try connecting to the database via the command line. If that doesn't work then check the username, password, dbname etc.
mysql --user=root --password=admindb#123 --host=192.0.0.0 moodle

MySQL Operational Error

I am trying to upload data into a MySQL database, but I am having trouble doing so. The error I receive when I try to run my code is 2003, Can't connect to MySQL server on 'db_host' ([Errno 11001] getaddrinfo failed). Does anyone know what this error means or how to fix it? I have included my code below.
import pymysql
import time
import good_morning as gm
DB_HOST = 'db_host'
DB_USER = 'db_user'
DB_PASS = 'db_pass'
DB_NAME = 'db_name'
conn = pymysql.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASS, db=DB_NAME)
kr = gm.KeyRatiosDownloader()
fd = gm.FinancialsDownloader()
kr_frames = kr.download('AAPL', conn)
fd_frames = fd.FinancialsDownloader()

SphinxQL + sphinxsearch table doesn't exists

Today I was trying to use sphinxsearch with SphinxQL but something going bad =\
First I installed sphinxsearch then I configured it, after that I created index forum_index using indexer --all. All finished without errors.
Then I included SphinxQl to my project, typed host and port which is listening sphinx and tried to make a query like in ReadMe of SphinxQL:
// create a SphinxQL Connection object to use with SphinxQL
$conn = new Connection();
$conn->setParams(array('host' => 'localhost', 'port' => 9306))
;
But it caused a database access error:
access denied www-data#localhost password NO
After that I set parameters of username and password in SphinxQL using
mysqli::real_connect()
Previous errors disappeared
Then I tried to make a test query:
$query = SphinxQL::create($conn)->select('column_one', 'colume_two')
->from('forum_index');
$result = $query->execute();
But I get an error:
table forum_index doesn't exists
I have a feel that my SphinxQL doesn't see sphinx or sphinx config and tries to make a simple query.
Have you any idea what's going wrong?
Please go to command line use the following command
mysql -P9306 --protocol=tcp --prompt='sphinxQL> '
Once get sphinxQL prompt enter the following command
sphinxQL> show tables;
If you set up everything correctly you can see the forum_index table in the list. Else check your searchd configuration section in your sphinx.conf file for proper configuration. My configuration look like this
searchd {
listen = 9315
listen = 9306:mysql41
log = /Users/XXXX/projects/sphinx/data/searchd.log
query_log = /Users/XXXX/projects/sphinx/data/query.log
read_timeout = 5
max_children = 30
pid_file = /Users/XXXX/projects/sphinx/data/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
workers = threads
thread_stack = 1024K
}
I solved my problem by setting host = '127.0.0.1' in SphinxQL params

Connect to mysql server through ssl in Zend Framework

Single DB connection (resource configuration) from application.ini:
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "mysql1"
resources.db.params.username = "dbuser"
resources.db.params.password = "dbpass"
resources.db.params.dbname = "dbname"
;resources.db.???
Multiple DB connection (resource configuration) from application.ini:
resources.multidb.mysql1.adapter = "pdo_mysql"
resources.multidb.mysql1.host = "mysql1"
resources.multidb.mysql1.username = "dbuser"
resources.multidb.mysql1.password = "dbpass"
resources.multidb.mysql1.dbname = "dbname"
;resources.multidb.mysql1.???
I don't believe connecting to MySQL with SSL is currently supported in Zend. However, Zend Issue Tracker ticket #6140 may be of help to you.