Connecting MySQL with Ruby on Rails
Ruby on Rails and MySQL are both leading technologies in Web Development, here is a guide for connecting MySQL with Ruby on Rails.
Step 1: Install MySQL in the System
MySQL is a powerful database management system used for organizing and retrieving data. To install MySQL, open terminal and type in these commands: sudo apt-get install mysql-server libapache2-mod-auth-mysql During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, it is very easy to set the password later from within the MySQL shell. Once you have installed MySQL, we should activate it with this command: sudo mysql_install_db Finish up by running the MySQL set up script: sudo /usr/bin/mysql_secure_installation The prompt will ask you for your current root password. Type it in. Enter current password for root (enter for none): OK, successfully used password, moving on…
Step2: Create a Database in the Local
To login to mysql, run following commands on terminal mysql -u root -p At the Enter password: prompt, enter root’s password now u can create a new database using create database your_db_name ;
Step3: Create a New Rails App using Mysql
rails new app_name -d mysql
If we start a rails app using -d mysql then it automatically changes gem ‘sqlite3’ from your Gemfile and add the gem ‘mysql2’
Step4: Change the Database.yml with your Mysql Database Name that we Created Earlier
Go to cd your_app_name/config/ and open database.yml. Rename it as the following:
development: adapter: mysql2 database: your_db_name host: localhost username: your_mysql_user_name password: root's password encoding: utf8
That’s it now u can create the rails application using MySQL. Meet and hire professional Ruby on Rails & MySQL developers at Cubet Techno Labs and get your ideas converted to result-oriented applications within your budget.