Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Connecting to PlanetScale from Ruby

These examples demonstrate how to connect a Ruby application to a PlanetScale database using two different methods:

  • Rails — Connect a Rails application to PlanetScale
  • mysql2 gem — Connect a Ruby application to PlanetScale using the mysql2 gem.

Follow the instructions below to find and insert your PlanetScale credentials.

Getting the credentials

  1. In the PlanetScale dashboard, select the database you want to connect to.
  2. Click "Branches" and select the branch you want to connect to.
  3. Click "Connect".
  4. Select "General" or "Rails" from the "Connect from" dropdown.
  5. If the password is blurred, click "New password".
  6. Copy the credentials. You won't be able to see the password again.

Connecting your database

To connect, find the method you're connecting with below and follow the instructions in that section.

Option 1: Rails

  1. Copy the contents of rails/database.yml into your connection file.
  2. Replace the placeholders for HOSTNAME, DATABASE, USERNAME, and PASSWORD with the copied values from the previous section. We encourage you to move these placeholder values into your .env file.
  3. To ensure a secure connection, you must fill in the SSL certificate path. This is the value for sslca.

This path depends on your system, so you need to paste in the appropriate value.

You can find configuration information for your system in our Secure connections documentation.

Option 2: mysql2 for Ruby

  1. Require mysql2 in your Gemfile:
gem "mysql2"
  1. Copy the contents of mysql.rb into your connection file.
  2. Replace the placeholders for HOSTNAME, DATABASE, USERNAME, and PASSWORD with the copied values from the previous section. We encourage you to move these placeholder values into your local environment variables file.
  3. To ensure a secure connection, you must fill in the SSL certificate path. This is the value for sslca.

This path depends on your system, so you need to paste in the appropriate value.

You can find configuration information for your system in our Secure connections documentation.

More resources

Rails resources

Next steps