![]() |
Connecting MySQL to Ruby on Rails enables developers to leverage the powerful relational database management capabilities of MySQL within their Rails applications. This process involves installing MySQL and Rails, configuring the database settings, and setting up the necessary gems. By integrating these technologies, developers can efficiently manage database operations and execute SQL queries seamlessly. Table of Content Connecting MySQL1. Install MySQLEnsures your package list is up-to-date and install the MySQL server package the MySQL development libraries using the below commands. sudo apt update ![]() Install MySQL Start the MySQL server using the below command. sudo systemctl start mysql
2. Install RailsFirst insure that you have Ruby installed on your system. You can install Rails using RubyGems package manager. gem install rails
Set up a new Rails app configured for MySQL, this command will change the default database to MySQL. Then get to your working directory. rails new myapp -d mysql ![]() Create new rails app 3. Configure DatabaseEdit ‘myapp/config/database.yml’ with MySQL credentials and specifies database connection settings for your Rails app. development: 4. Install GemInstall the ‘mysql2’ gem which is helpful for working with MySQL in Rails applications. gem install mysql2
![]() Install mysql2 Gem 5. Create and Migrate the DatabaseSet up the MySQL database for your Rails environment and run the database migrations. rails db:create 6. Run SQL Queries from TerminalNow you can run MySQL queries from command by logging in to your account. mysql -u <user_name> -p |
Reffered: https://www.geeksforgeeks.org
Ruby |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 18 |