See which MySQL database is currently in use
When you work in the MySQL console and you want to see which database is used, type:
SELECT database();
The result you see is the database you would activate with
USE database_name;
Related cards:
Capistrano: How to find out which version of your application is currently live
When deploying, Capistrano puts a REVISION
file into your application's release directory. It contains the hash of the commit which was deployed.
If you want to know the currently deployed release, simply SSH to a server and view that file.
``...
Don't ever use the float type for database columns
Like in any language, a FLOAT
will eventually corrupt data due to rounding errors.
Please use DECIMAL
, which has [well-defined behavior for rounding and range overflows](https://makandracards.com/makandra/1177-how-decimal-columns-deal-with-nu...
Capistrano 2: Which Capistrano hooks to use for events to happen on both "cap deploy" and "cap deploy:migrations"
When deploying an application with "cap deploy
" by default [1] you only deploy your code but do not run migrations. To avoid an application to be running with code which requires database changes that did not happen yet you should use `cap deplo...
Use DatabaseCleaner with multiple test databases
There is a way to use multiple databases in Rails.
You may have asked yourself how you're able to keep your test databases clean, if you're running multiple databases with ful...
MySQL: Careful when using database locks in transactions
We tend to use database transactions as a magic bullet to get rid of all our concurrency problems. When things get really bad, we might even throw in some locking [mechanism](https://makandracards...
Workflow: How to use a key management service to encrypt passwords in the database
This is an extract from the linked article. It shows an approach on how to implement encrypted passwords with the AWS Key Management Service (KMS).
For most applications it's enough to use a hashed...
Simple database lock for MySQL
Note: For PostgreSQL you should use advisory locks. For MySQL we still recommend the solution in this card.
If you need to synchronize multiple rails...
MySQL will not use indexes if you query the wrong data type
When MySQL refuses to use your index, there's a number of things that you may be doing wrong. One of them might be conditions with improper data types.
An example
For example, let's assume you have a users
table with an email
field (`var...
MySQL: How to clone a database
Here is a way to create a duplicate of one database, with all its tables and their data, under a new name.
-
Make a dump of your source database:
mysqldump -uroot -p my_project -r my_project.sql
Or, if you only want to dump the datab...
List sizes of MySQL databases
Do you wonder which databases are actually taking up how much space but only have one huge ibdata1
in your /var/lib/mysql
and the directories inside your mysql data directory don't represent the actual database sizes? This is for you!
Run fro...