Mysql and Nitrious IO - mysql

I just created a rails box in Nitrous IO. Rails boxes come predefined to use sqlite3 but I want to use mysql2. Since I can't use mysql from the box because it fires up an error that it can't connect to a socket, they can connect the box to a free database service in Heroku. I created an account in Heroku, and logged in from my box to heroku. I am having problems linking the database (cleardb) to the rails box in NitrousIO, since they only show procedure to link a postgres db.
My database.yml file has the following:
development:
adapter: mysql2
encoding: utf8
database: testdb_development
pool: 5
username: root
password:
host: localhost

Did you already configure the development settings within the database.yml file? You will need to change the host, username, and password fields which you listed above to match the settings of your cleardb.
Here is another post which states how to retrieve your host database URL: Remote connect to clearDB heroku database
On the top corner click on Addons and then select ClearDB MySQL
Database. Once there, click on your database and choose the 'Endpoint
Information' tab. There you see your username/password. The URL to the
database can be acquired by running heroku config --app
In my case, it was something like:
mysql://user:pass#us-cdbr-east.cleardb.com/TABLE?reconnect=true What
you need is this part: us-cdbr-east.cleardb.com

[Update January 2014]
Boxes should use Autoparts to manage packages / services like MySQL, Postgres, Redis, etc...
Please see this article for more information:
http://help.nitrous.io/mysql/

Related

Cant Build Schema In Local Instance MySQL

I want to create a new local instance in MySQL Workbench 8.0. I already create one local connection, but when I try to create a schema the Execute query button is disabled and i cant right click on Navigator field to add schema. I follow many instruction on internet, but they all seems to have no problem when adding a schema.
The detail of local connection that I created is like this
Connection Method: Standard (TCP/IP)
Hostname : localhost
Port: 3306
Username: root
And when I click the Test Connection button, it says Can't connect to MySQL server on 'localhost' (10061)
Anyone know what I'm missing in both step and requirement?

heroku rails app:test RDS mysql as suggested by Heroku June 2016 article?

has anyone else had issues with this process recently?
I ended up creating a fresh basic rails app, deploying to heroku, then trying to add RDS connectivity. really hope someone can spot my errors i'm going nuts!
why even when trying to run production 'mode' locally, its still trying to use db user/pass localhost?? i wonder if there is some config hidden in rails somewhere
second step, have i missed something obvious? I've tried a basic app from absolute scratch following all the guides, still cannot connect
is the error cannot connect via sock an indication of bad config elsewhere, it shouldn't be using any sockets, only port access?
thanks
Ben
followed
this for basic heroku app https://devcenter.heroku.com/articles/getting-started-with-rails4
then this for rds https://devcenter.heroku.com/articles/amazon-rds
then this to double check i had right cert: Specify SSL for Heroku external MySQL database connection
app configured as follows
updated rails app to use database_url
RDS created in North Virgina (this is same as heroku i believe, but lets not worry about latency just yet)
security group inbound port 3306 0.0.0.0/0 (firstly I tried specific rds created group, I then tried the full default, based on this: Connecting Heroku to RDS using MySql2)
set up SSL in grants GRANT USAGE ON *.* TO '<usr>'#'%' REQUIRE SSL; (see extract below)
added cert to heroku repo (amazon-rds-ca-cert.pem seems to have all the intermediates in it)
added DATABASE_URL=mysql2:://<usr>:<pwd>#pure-reaches-94579.cfc59p8se1g1.us-east-1.rds.amazonaws.com/purereaches?sslca=config/amazon-rds-ca-cert.pem
rebooted rds instance at every try
i even tried simple RDS passwords thinking that complex ones somehow messed with the url
next step of investigation
I attempted to run production locally but use database url to connect to RDS:
$ export RACK_ENV="production"
$ export RAILS_ENV="production"
$ export SECRET_KEY_BASE="blah"
$ export DATABASE_URL="mysql2:://usr:pwd#pure-reaches-94579.cfc59p8se1g1.us-east-1.rds.amazonaws.com/purereaches?sslca=config/amazon-rds-ca-cert.pem"
$ rails server -e production
...
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: NO)):
mysql2 (0.4.5) lib/mysql2/client.rb:89:in `connect'
...
this reveals that the standard rails app config trying to connect to local host still
what am i missing here!?
details
cannot login via ssl on cli - obviously not good
$ mysql -h pure-reaches-94579.cfc59p8se1g1.us-east-1.rds.amazonaws.com -u <usr> -p purereaches --ssl-ca=$HOME/Documents/repositories/baseherokuapp/baseherokuappconfig/amazon-rds-ca-cert.pem --ssl-verify-server-cert
Enter password:
ERROR 2026 (HY000): SSL connection error: SSL_CTX_set_default_verify_paths failed
rails app will not connect
gives mysql2::Error (Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)):
info
i'm worried its still trying to use sock... is this a red herring?
database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
# for next step test
# rails app error saying cannot connect to root # localhost!
development:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
production:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
grants table
mysql> show grants;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for purereaches#% |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'purereaches'#'%' IDENTIFIED BY PASSWORD <secret> REQUIRE SSL WITH GRANT OPTION |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.22 sec)
So it seems I've been staring at the same thing too long. Thank you heroku support for pointing out I had two ":" in my string! What a muppet I am.

Connect to MySQL using Ruby on Rails

Im currently working with ruby on rails, which is an area that I'm entirely new to. I'm using MAMP and have set up a local MySQL database called my_db with a table called employees https://localhost/phpmyadmin.
Is there a way to connect to this database using ruby on rails and write to this table in the database. I have tried many examples but all of them show you how to connect to a mySQL db installed natively. I can't seem to work out how to connect to a database that lives in MAMP. Any suggestions?
Rails connects to whatever's defined in config/database.yml, so you should be able to connect in much the same way any PHP code does:
development:
driver: mysql2
host: localhost
username: my_username
password: my_password
database: my_database_name
Generally you connect over host with an optional port parameter.

OpsWorks gets deployed, but non of my actions work. Is my database.yml file messing things up?

When I run my rails server locally with a local mysql server, my endpoints work fine and things are being inserted and updated to the mysql database and everything is just beautiful.
When I deploy to AWS OpsWorks, however, the application get's deployed and I'm able to see what's in the /public folder, but all my actions don't work and I'm not quite sure how to debug this.
When I check the log, see that bundle install gets called, and even then following...
[2014-07-13T14:37:34+00:00] INFO: No database adapter specified for bgs_api, guessing
[2014-07-13T14:37:35+00:00] INFO: Looks like bgs_api uses mysql2 in its Gemfile
.. but nothing regarding the actual creation of the tables or execution of the migrations.
About my instance and app...
I have one EC2 instance that has both the Rails and MySQL layers on it.
I'm using a database.yml file, but I'm not sure if this means that I can ignore putting in the custom JSON when deploying the application. Which is what I'm currently doing.
Here is my database.yml file
development:
adapter: mysql2
encoding: utf8
reconnect: true
database: xyz #name for local database defined by me
username: abc #username for local database user defined by me
password: 123 #password for local database user defined by me
pool: 5
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: true
database: xyz #name for opsworks database defined by me
username: root #username for opsworks database defined by opsworks
password: abc #password for opsworks database defined by opsworks
pool: 5
host: localhost
One particular thing I'm not sure about is the production host value... I imagine it would be localhost because this get's run on the ec2 insatnce.
Any help or direction for debugging would be of great help. Thank you!
You need to send in the database details via custom JSON. This is because the APP doesn't have the connection details automatically from the configurations. Even if you do add it into the codebase, it'll get over written by the recipes.
{
"deploy":{
"app_name":{
"database":{
"password":"",
"adapter":"mysql2",
"username":"",
"database":"",
"host":"localhost"
}
}
}
}
You need to run normal task that does create your database etc. This is something you should do to seperately as part of installing the app. A good option would be to use the deployment hooks : opsworks hooks

How do I connect a mysql database file to a local ruby on rails application

I have a database file (name.sql) that was sent to me that I am supposed to connect to a rails app locally hosted on my mac, that I downloaded (forked?) from github. How do I set up my database.yml file to connect with the sql files.
You can't connect a Rails application directly to a SQL file. The Rails application gets its data from a database server and you import the contents of the SQL file into a database hosted by the server.
You can download a DMG archive which will install MySQL Community Server on your Mac from http://dev.mysql.com/downloads/mysql/#downloads
That download also includes a handy Preference Pane for starting and stopping the server.
Once you have MySQL up and running then you should set a password for the root user (i.e. the database system administrator) using
mysqladmin -u root password "secret"
—Obviously replace secret with the real password you want to use.
Then you can set up the database.yml file for the Rails application. For an application named app it would look like this:
development:
adapter: mysql
database: app_development
username: root
password: secret
host: localhost
test:
adapter: mysql
database: app_test
username: root
password: secret
host: localhost
production:
adapter: mysql
database: app_production
username: root
password: secret
host: localhost
Note that typically in production you'd create a separate limited privilege database user account for the Rails application to connect to MySQL with, but for development on your local machine the root account is fine.
After this step you can run rake db:create from the root of the Rails application within the Terminal. This command will create the app_development database in MySQL (rake db:create:all creates the test and production databases too). Finally, you can import your SQL file by entering the following command in the Terminal:
mysql -u root -p app_development < path/to/file/name.sql
You will be prompted for the MySQL root password. Replace path/to/file with the full path to the SQL file if it's not within the Terminal's current directory. For example, use ~/Desktop/name.sql if it's on your desktop.
Probably easiest: you need to run a database server on your mac. Then import your data into your database server.
Tutorials on installing rails on a mac will also talk about how to install the local database server and setting up the database.yml file