Does rails set anything in a mysql database? - mysql

Basically, if I have two rails applications, with different database.yml settings, both connecting to the same database, will they conflict with each other?
Or is database.yml specific to the local application?
Essentially, does rails create just a raw database connection like mysql workbench would? Or is there more to it?

The .yml file is simplyba connection config for your app. Its totally fine to connect to the same app with different .yml

Related

How to config mysql with django and phpmyadmin

I am using django for my backend and mysql for database on nginx webserver on digitalocean. I want to use phpmyadmin to manipulate my database. Is there a way to do it?
Thank you.
Install phpmyadmin and manipulate the database however you want. You can setup Django to use the existing database from there.

Migrating a local mysql database to heroku postgres from a cakephp application

Hi I'm trying to migrate a database that was created with cakePHP on a local MYSQL database. I know that in rails the solution is to install the postgres gem that will handle the migration, but I'm wondering more specifically about cakePHP.
I've generated a sqldump of the mysql database using the solution here:
http://book.cakephp.org/2.0/en/console-and-shells/schema-management-and-migrations.html
I've also installed postgres locally onto my machine and am able to connect to my remote empty HEROKU database from the command line by using heroku pg:psql
However, if I run the SQL dump file directly in the console I get an error called SSL SYSCALL error: Software caused connection abort. This apparently is because as a DEV / Free database account you are restricted from entering SQL commands directly.
So, that would suggest that I would have to go and use something like
heroku db:push localdatabase herokudatabase
But that produces the error Sequel::AdapterNotFound -> LoadError: 193: not a valid Win32 application
Any ideas how I might manage this migration, bearing in mind that as it's a CakePHP application I do not have the option of just installing a PostGres gem?
Thanks for any direction, or thoughts.
You almost certainly want to install Postgres locally on your machine, and get your database and code working correctly there. Once it's set up, it's easy to do a dump of your Postgres database and upload to Heroku.

How can I find the database I created for my Rails application locally and load it to a server?

I am using Lynda.com Rails tutorial. I created a MySQL database for my Ruby on Rails application simple_cms.
The database is called simple_cms_development.
Let's say I want to move this database into a new server, where do I find it?
I am running rvm, and I saw mysql is inside this rvm, but I am not able to access it. I searched my computer for simple_cms_development , and couldn't find anything either. Any ideas? Thanks
Copy the source code from the original machine to the new machine, or get it onto your new machine from a remote repository using git.
Run rake:db:create in the application directory on your new machine. This is assuming you have MySQL running on the new machine.
Use either the mysql client or the mysqldump utility to get a dump file of your MySQL database from your original machine.
Copy the dump file to the new machine and load it into the database using the MySQL client.
You can google the details of how to use git, dump and load MySQL, etc.
RVM is a tool for managing Ruby versions and gems. A Rails project backed by a MySQL database will need to use some Ruby gem (like mysql2) to allow the Rails app to talk to the MySQL database. All you're seeing in the .rvm directory is the gem. I'm not sure if the usual MySQL gems provide functionality to dump or load a database, at any rate you may as well use the MySQL client directly.

How does Rails know where the MySQL database is?

I finally got a MySQL database hooked up to a Rails 3.2 app after spending half the day figuring it out.
What I don't understand though is how Rails knows where to find the database?
With the default Sqlite3 it's easy enough in that it's embedded in the app so it's just a matter of specifying the path in the database.yml (db/devlopment.sqlite3).
But, when it's MySQL, I thought I'd have to specify the path of the database I'd created from the MySQL command line. Turns out I don't have to, all I have to do is give the name of the database and user login credentials.
So when I run a migration in Rails, how does it know where the database is?
That's called a reasonable default. Take a look in your database.yml file, you might find a line like this:
socket = socket: /tmp/mysql.sock
AFAIK, if that's not explicitly there, it is used as the default in the absence of other parameters (such as host and port).
Actually, Rails doesn't know anything about it. The modules which handle the connection to the database are the adapters used by Active Record. Rails only provides a kind of "configuration convention" in the case of the database.yml file to make it somehow "common" to all database possibilities, but internally they use this information to setup each database connection in its own unique protocol. I don't know about SQlite, but the mysql and mysql2 handlers are not mantained by the rails team
https://github.com/brianmario/mysql2
Here you can check out the interface Rails/ActiveRecord uses to setup the MySql Connection.
So, to sum it up, Rails doesn't know. It just needs the information you setup in the database.yml to infer which adapter they should use (go to your database.yml and you'll see something like "adapter: mysql2" or "adapter: "sqlite") and the necessary information to establish the connection. As #pjam described, the protocol used for accessing the mysql service externally is expressed by the pattern mysql://localhost:3306/DB_NAME?user=YOUR_USER_NAME&password=YOUR_PASSWORD , and this is actually how the adapter sets the connection up. Just it is not done by Rails.
I believe it finds it with the url of your local database, which is something like
mysql://localhost:3306/DB_NAME?user=YOUR_USER_NAME&password=YOUR_PASSWORD
So it only needs DB_NAME, YOUR_USER_NAME & YOUR_PASSWORD, which are provided in your database.yml

Grails DataSource for remote MYSQL database access and migrations

Is it possible for locally running grails application to access and update remote MySQL db?
Assume the remote server is linux on which tomcat, MySQL are installed in the usual places.
Assume remote URL is accessed as tom#189.124.24.249. So grails needs to access the db as the user 'tom' or does it need to be the root user or mysql user??? Does the password of user tom need to be specified in the DataSource.groovy? In MYSQL the db test_db is configured to be accessed with user name 'guru' and password 'secret'.
If the same grails application is also running on the remote server accessing that remote db, a locally running instance of grails application accessing the same remote db should not cause any problems??
Assume the remote db name is test_db.
I need this also in context with liquibase grails plugin and database migrations. I need to run grails migrate command against the remote db to synchronize it with local db.
A side question: how do I synchronize local db in which table data is already populated to remote fresh newly created db with no data? This seems to fall under the domain of db content migrations which is not covered by the grails plugin as far as I know. I would like to know what would be the correct approach to this in the context of a grails application.
you just need to set the proper credentials in the Datasource.groovy and it all should work fine. We are running our app in a production environment and the database server is on a different box.
I dont think that two applications accessing the database server should be a problem.
Can't help with the side question... sorry
I believe, it's mostly a duplicate of Liquibase Grails database migrations
For side question: after Grails migrates structure, mysqldump or whatever backup/restore procedure should work.