简体   繁体   中英

Alter MySQL auto_increment with Heroku ClearDB addon

My Rails app is hosted on Heroku. I have a problem with MySQL incrementing by 10: Large Auto Increment IDs

I really want to change it to 1, and I have found the SQL command for that. However, I cannot figure out how to connect to mysql via Heroku to perform it. Is there a workaround? Is it even possible?

You can connect to the database hosted by ClearDB using your local mysql command line client application. First you'll need to check your database URL to get the necessary connection details, so run heroku config and you should see a line that looks something like this:

CLEARDB_DATABASE_URL: mysql://abcdef01234567:9876543@us-cdbr-iron-east-01.cleardb.net/heroku_fedcba76543210?reconnect=true

The URL contains the username, password, host and database name in the format:

mysql://username:password@host/database?reconnect=true

With those four pieces of information you can connect to your database. Using the (made up) example database URL as an example:

mysql --user=abcdef01234567 --password9876543 --host=us-cdbr-iron-east-01.cleardb.net heroku_fedcba76543210

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