I am really new in Ruby on Rails. I have read this tutorial and it sounds really easy.
But how can I connect to my database (MySQL) or what does Rails use? In php I'd use...
mysql_connect("...","...","...");
mysql_select_db("...");
I have searched google and cannot find any useful tips.
The mysql2 Ruby gem provides an API for connecting to MySQL, performing queries, and iterating through results; it is intended to support MySQL 5.6, 5.7, and 8.0.
Have a look into the configuration file config/database.yml
You need to setup your configuration there. Here is an example for the production environment:
production:
adapter: mysql2
encoding: utf8
database: example
pool: 10
username: example
password: secure
socket: /var/run/mysqld/mysqld.sock
reconnect: true
In addition to that you have to add gem 'mysql2'
in your Gemfile and run bundle install
.
You don't have to do those things manually, check this: http://guides.rubyonrails.org/configuring.html#configuring-a-database
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With