Reset MySQL query cache
To clear the query cache in your MySQL database manually, e.g. for database profiling, execute the following command in your MySQL console:
RESET QUERY CACHE;
Related cards:
MySQL: Disable query cache for database profiling
If you want to see how long your database queries actually take, you need to disable MySQL's query cache. This can be done globally by logging into a database console, run
SET GLOBAL query_cache_type=OFF;
and restart your rails se...
Reset mysql root password
This article describes how to reset MySQL's or MariaDB's root password on your workstation. It's meant for local development purposes only, don't do this in production. This article will also help you if you have a fairly recent MariaDB version ...
uninitialized constant MysqlCompat::MysqlRes (NameError)
If you get a stacktrace complaining about uninitialized constant MysqlCompat::MysqlRes
a system library update might broke your gem.
You might have [switched from MySQL to MariaDB](https://makandracards.com/makandra/51171-running-rails-2-apps-w...
ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection
I recently experienced the error ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection
. Apparently this happens when there is a timeout during query execution. In order to fix this you can reconnect to your db.
Therefore either...
How to enable MySQL query logging
This will make MySQL log all received queries so you can see for yourself what happens on the database level.
Don't switch this on for production machines!
- Edit your
my.cnf
:
sudo vim /etc/mysql/my.cnf - In the
[mysqld]
section, a...
MySQL: Do not use "WHERE id IN (SELECT ....)"
Note: This applies specifically to MySQL. In PostgreSQL for example, this is not an issue.
If you care about performance, never use a query like
UPDATE users SET has_message = 1 WHERE users.id IN (SELECT user_id FROM messages)
MySQL doe...
mysqltuner.pl
This Perl script will run diagnostics on your MySQL database and recommend changes to your MySQL configuration.
Discarding cached SQL query results in ActiveRecord
ActiveRecord caches results of SQL queries. If you want to discard the cached results for one model, you can call [MyModel.connection.clear_query_cache
](http://api.rubyonra...
MySQL will not use indexes if you query the wrong data type
When MySQL refuses to use your index, you can do a number of things 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 (varchar
) which is index...
Caching in Rails < 6.1 may down parts of your application when using public cache control
Proxy caching is a good feature to serve your publicly visible application content faster and reduce load on your servers. It is e.g. available in nginx, but also affects proxies delivered by ISPs.
Unfortunately, there is a little problem in Rail...