Connect the app from the VPS itself, not from your laptop: install and supervise MySQL (or obtain credentials for a managed MySQL service), create a database and least-privilege account, add the mysql2 adapter, expose the production credentials through DATABASE_URL or protected deployment secrets, prepare the schema, and test a database-backed request. The connection is complete only when the Rails process can reach the intended host, authenticate as the application user, and run a query in the production environment.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
What the connection consists of
A Rails deployment has three separate pieces that must agree:
As an Amazon Associate I earn from qualifying purchases.
Recommended Free Tools
- MySQL endpoint: a local MySQL server on the VPS, or a remote managed MySQL service. You need its hostname or socket, port, database name, username, password, and any TLS requirements.
- Rails adapter: the
mysql2gem, bundled on the server in the same environment as the application. - Production configuration:
config/database.ymland/orENV['DATABASE_URL'], with credentials supplied at deploy or process start rather than committed to Git.
Rails supports MySQL and MariaDB through the mysql2 adapter. The Rails configuration example uses utf8mb4, which is the appropriate character set for full Unicode text. A successful local connection does not prove the VPS connection will work: the server may have different DNS, firewall rules, credentials, socket paths, TLS policy, Ruby gems, or environment variables.
Choose where MySQL runs
| Arrangement | What you administer | Network path | Best fit |
|---|---|---|---|
| MySQL on the same VPS | MySQL installation, updates, backups, disk capacity, users, and recovery | Unix socket or loopback TCP; no public database port is required | A small deployment where you want a simple private path and can operate the database |
| Managed MySQL | Rails credentials and application-side configuration; the provider handles much of the database patching and infrastructure | Private network or restricted TCP connection to the provider endpoint, often with TLS | A team that prefers less database administration or needs a separately scaled database |
Local MySQL usually reduces network latency and monthly service cost, but the VPS becomes a single failure domain and you own backup and patching work. A managed service can simplify availability and maintenance, while adding network configuration, provider-specific TLS settings, and a separate bill. Whichever option you choose, keep the endpoint private and permit connections only from the application host or private network.
#1 Best Overall
- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
Prepare the VPS
Confirm the operating environment
Use an Ubuntu LTS image or another Linux distribution supported by your deployment tooling. Before touching the database, verify that the VPS has the Rails runtime, a working Ruby installation, Bundler, your application dependencies, and a process supervisor. Record the Linux user that will run Rails; it should not be the MySQL administrator account.
ruby --version
bundle --version
rails --version
If MySQL is remote, also confirm that the VPS can resolve the database hostname and that your provider’s private network, security group, or firewall allows the database port from this host. Do not open a database port to the entire internet merely to make an initial test pass.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteInstall MySQL locally (when selected)
On Ubuntu, install the distribution’s MySQL server package and client, then check the systemd unit. Package names can vary by distribution release, so use the package manager’s package for “MySQL server” rather than copying a package name intended for another operating system.
sudo apt update
sudo apt install mysql-server mysql-client
sudo systemctl enable --now mysql
sudo systemctl status mysql
Ubuntu documents MySQL as the mysql.service systemd service. The status command should show an active running service before you configure Rails. Run the vendor’s security setup after installation to remove insecure defaults and review authentication options:
sudo mysql_secure_installation
If you edit a MySQL configuration file or add a systemd override, restart the daemon after validating the change. When a systemd override itself changes, reload systemd first, then restart MySQL:
sudo systemctl daemon-reload
sudo systemctl restart mysql
sudo systemctl status mysql
Do not assume a restart succeeded because the command returned quickly; read the status output and MySQL’s journal when it does not come back.
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
Create a production database and application account
Use a dedicated account
Log in locally as an administrative MySQL account only for database administration. The Rails process should use a separate account with a password stored in your deployment secret store. Never run Rails as MySQL root, and never commit the production password to source control.
sudo mysql
Choose a database name and account that identify this application and environment. The following example uses rails_production and rails_app; change them to your own names.
CREATE DATABASE rails_production
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
CREATE USER 'rails_app'@'localhost'
IDENTIFIED BY 'use-a-long-random-secret';
GRANT ALL PRIVILEGES ON rails_production.*
TO 'rails_app'@'localhost';
FLUSH PRIVILEGES;
The account host is part of the MySQL identity. 'rails_app'@'localhost' is intentionally different from 'rails_app'@'%': it permits local connections only and avoids creating a user that can authenticate from every source address. If Rails connects over TCP from another machine, create a grant for the application’s private source address or private subnet instead of using a global wildcard whenever possible.
Grant only what the deployment needs
A normal Rails application must read and write its own tables and run migrations. Granting privileges on that application’s database is different from granting global administrative privileges. Do not add GRANT ALL ON *.*, file privileges, shutdown privileges, or user-management privileges to the Rails account. If your organization separates migration and runtime identities, use a stronger migration account for deploy jobs and a narrower runtime account for requests.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Check the result before leaving the administrative session:
SHOW GRANTS FOR 'rails_app'@'localhost';
EXIT;
Add the Rails MySQL adapter
Ensure the application’s Gemfile includes the adapter:
Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
gem 'mysql2'
Run Bundler in development, commit the resulting lockfile, and deploy that bundle to the VPS. Build failures commonly mean the server lacks a compiler, MySQL client development headers, or the libraries required by the selected mysql2 version. Install the prerequisites for your Linux distribution, then run:
bundle install
bundle exec ruby -rmysql2 -e 'puts Mysql2::Client.info'
The second command checks that the gem can load in the deployed Ruby environment. It does not prove that credentials or network access are correct; those are tested by Rails itself.
Configure production credentials
Preferred pattern: DATABASE_URL
Rails can read connection details from config/database.yml or from ENV['DATABASE_URL']. The Rails Guides recommend making the production URL explicit so the password remains outside source control:
production:
url: <%= ENV['DATABASE_URL'] %>
Set the variable in the service manager, deployment secret store, or release environment—not in a committed file. A TCP URL has this shape:
mysql2://rails_app:[email protected]:3306/rails_production
Use the actual username, secret, hostname, port, and database name for your environment. Port 3306 is shown as the conventional MySQL port; include a different port when your service uses one. If a password contains characters reserved by URLs, percent-encode them. An unescaped @, :, #, ?, or slash can change how the URL is parsed and produce an authentication or host error that looks unrelated to the secret.
For a local Unix-socket connection, either let the adapter use the local socket defaults or specify the socket in the YAML configuration. A socket avoids a network firewall path but requires Rails and MySQL to share the host and a compatible socket location. A remote service normally uses TCP and may require TLS parameters supplied by the provider.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Rank #4
- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
Alternative: explicit database.yml
If your deployment system renders a protected configuration file, an explicit production block can be useful:
production:
adapter: mysql2
encoding: utf8mb4
database: rails_production
username: rails_app
password: <%= ENV.fetch('MYSQL_PASSWORD') %>
host: db.internal.example
port: 3306
pool: 5
Keep the password expression tied to an environment variable or secret manager. Do not place the literal production password in this file. Do not define both a stale hard-coded block and a different DATABASE_URL and then guess which one Rails will use; choose one authoritative source and inspect the rendered production configuration safely.
The pool: 5 value mirrors the Rails MySQL example, not a universal capacity recommendation. Set the pool deliberately for the number of Puma (or other application-server) threads and the MySQL server’s connection limit. A pool that is too small makes requests wait for a connection; one that is too large can exhaust MySQL connections, especially when several worker processes each have their own pool.
Handle local sockets, TCP, and remote MySQL
Local socket
A Unix socket is local to the VPS and does not expose MySQL on a network interface. It is a good fit when MySQL and Rails are on the same host. If Rails reports that the socket file cannot be found, verify the socket path in MySQL’s server configuration and the path expected by the client library. A socket error is not fixed by changing the password.
Local or private TCP
TCP is useful when Rails runs in a separate container, VM, or host. Bind MySQL to a private interface, restrict the host firewall to the application source, and verify that the MySQL account’s host component matches the source address. Test name resolution and the port from the Rails host before debugging Rails configuration.
getent hosts db.internal.example
nc -vz db.internal.example 3306
A successful TCP probe means the route and firewall permit a connection; it does not authenticate the MySQL user.
Best Value
Managed MySQL
Use the provider’s endpoint, database name, username, password, port, certificate requirements, and private-network instructions exactly as issued. Prefer a private address. If the service requires TLS, configure the CA certificate and verification settings in the adapter or deployment environment rather than disabling verification. Keep the certificate file readable by the Rails service account but not publicly accessible.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Prepare the production schema
Deploy the application code and bundle before changing the schema. Set RAILS_ENV=production and make the production secret available to the command. Use the task appropriate to your Rails version and release process:
RAILS_ENV=production bundle exec rails db:prepare
db:prepare is convenient for an idempotent create-or-migrate workflow where supported. A team that explicitly separates first-time creation, schema loading, and migrations may instead run its established db:create, db:schema:load, or db:migrate task. Confirm the target before any destructive operation: print the effective host and database through a safe diagnostic, inspect the deployment environment, and verify the database name with an administrative read-only check. Never point a production migration command at a shared staging or personal database by accident.
Rails enables MySQL advisory locks by default for concurrent-safe migrations. Leave that behavior in place unless your deployment design requires disabling it explicitly and you understand the concurrency consequences.
Start Rails and verify from the app host
Run a database-backed check
Start Puma or your selected application server under the same supervisor that will keep it running after logout and reboot. Then call a health endpoint that performs a real database query, such as an endpoint that reads a lightweight record or runs the application’s normal health check. A process that merely returns HTTP 200 without touching MySQL cannot validate the database connection.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteCheck the Rails logs while making the request. The expected result is a successful response and no new connection or authentication exception. Avoid logging DATABASE_URL or dumping the full Rails configuration, because either can expose the password.
Supervise both services
Keep MySQL under systemd and manage Puma with the same service manager or deployment tooling used for the rest of the VPS. Enable the services at boot, define restart behavior appropriate to your operations policy, and make sure the Rails service starts only after its secret files or environment have been made available. Rails’ current deployment guidance includes Kamal and an Ubuntu LTS server path; containerized deployments still need the same adapter, credentials, network policy, and migration discipline.
Diagnose a connection that works locally but fails on the VPS
| Observed symptom | Likely cause | What to check |
|---|---|---|
| “Can’t connect to local MySQL server through socket” | MySQL is stopped, Rails expects the wrong socket, or the app is actually in a container | systemctl status mysql, the configured socket path, and whether the Rails process shares the host filesystem |
| Connection timeout or “connection refused” | Wrong host or port, service not listening, firewall/security group, or private-network route | DNS resolution, a port probe from the VPS, MySQL bind address, and firewall rules |
| “Access denied for user” | Wrong secret, URL encoding error, or a MySQL grant whose host component does not match | The exact username and database in the effective environment, SHOW GRANTS, and whether the password contains reserved URL characters |
| Rails says the adapter is missing | mysql2 was not bundled, or the service uses a different Ruby/Bundler installation |
bundle exec ruby -rmysql2, the deployed lockfile, and the service’s executable path |
| Migration hangs waiting for a connection | Pool is too small for the process’s concurrency, or all MySQL connections are in use | Puma worker/thread counts, pool setting, MySQL connection usage, and long-running requests |
| Authentication works but migrations fail | The application account lacks a required schema privilege, or the command targets the wrong database | Effective database name, grants on that database, and the migration error’s exact SQL operation |
| Works in a shell but not under systemd | The service does not receive the same environment, working directory, Ruby, or secret files | The unit’s environment and credentials, service user, bundle path, and journal output |
Inspect the Rails exception first, then the network path, MySQL grants, and service logs. This order prevents changing database permissions when the real problem is a missing environment variable or blocked route.
Operate the connection safely after launch
- Backups: schedule and test restores for a local database; for managed MySQL, understand the provider’s retention and recovery point guarantees rather than assuming they cover every incident.
- Updates: patch Ubuntu, MySQL, Ruby, and the
mysql2bundle through a controlled release process. Read compatibility notes before changing a major database or adapter version. - Secrets: rotate the application password in the secret store and MySQL, then restart or reload the Rails service so it receives the new value. Revoke old credentials after confirming traffic uses the new account.
- Capacity: watch MySQL connection usage and Rails pool wait time. Recalculate the pool when you change Puma workers or threads; every process can create its own set of pooled connections.
- Configuration changes: validate MySQL configuration, run
sudo systemctl daemon-reloadafter changing a systemd override, restart MySQL, and verify the active service before sending traffic. - Migration safety: run one controlled migration release at a time, retain the advisory-lock behavior unless there is a documented reason to change it, and keep a tested rollback or restore plan for destructive changes.
Deployment model choices
| Model | Operational characteristics | Choose it when |
|---|---|---|
| Puma plus systemd on the VPS | Direct host networking, familiar logs and service controls, and straightforward rollback to a previous release directory | Your team is comfortable administering the host and wants minimal orchestration |
| Container or Kamal deployment | Images package Ruby and gems consistently; releases can be replaced or rolled back as units, but container networking and secret injection must be configured | You already operate containers and want repeatable image-based releases |
Neither model removes the database work. Both still require a valid mysql2 bundle, a reachable endpoint, least-privilege grants, protected secrets, an intentional pool size, and a migration procedure.
Quick Recap
Final connection checklist
- The VPS runs a supported Linux distribution and has the deployed Ruby, Bundler, Rails dependencies, and
mysql2gem. - MySQL is running under systemd locally, or the managed endpoint resolves and accepts traffic from the VPS over its private route.
- The production database uses the required character set, such as
utf8mb4, and exists on the intended server. - The Rails account is dedicated to the application, has only the required database privileges, and is not MySQL
root. DATABASE_URLor the protecteddatabase.ymlblock contains the correct adapter, credentials, host, port, and database; URL-reserved password characters are encoded.- The connection pool matches application concurrency and remains below the database’s practical connection capacity.
- The schema task ran with
RAILS_ENV=productionagainst the verified target database. - A health check or normal endpoint executed a database query successfully from the running Rails process.
- MySQL and Rails restart through the chosen supervisor, secrets are available after reboot, and backups and restore procedures are documented.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




