简体   繁体   中英

Start MySQL when Rails server gets started?

When I start my Rails 4.2 app locally I ofter get this error:

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I then type mysqld on my terminal and everything is fine.

Is there a way to start MySQL automatically every time the server gets started?

I am on Mac OS 10.11.5.

Thanks for any help.

Use Foreman to launch and shutdown several processes together. In your case, you need to list two processes in your Procfile :

web: bundle exec rails server
db: mysqld

Then run foreman start to start them all. Then Ctrl+C to stop them all.

Have you consider using a bash script to start up your server? So instead of manually running rails s , you have a script in which you have your command to run both mysqld and then rails s , and then just execute this script? Something like the following:

#!/bin/sh
mysqld
rails s

On the other hand, if you might want to consider starting MySQL automatically every time you laptop starts up so that MySQL is always running in the background, you can use launchctl for this :

sudo launchctl load -w com.oracle.oss.mysql.mysqld.plist

You can go to system preferences, go to the MySql Page, and then select the box that says "Automatically start server on startup". Other than that I dont think there is away to start the MySQL server when the just the rails server starts

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM