The post will contain some queries that may provide some useful actions or information on the database.
Get the size of all databases:
Get string before or after a specific character via MySQL
Here is my solution to a situation where I needed to select just parts of MySQL records using specific char as a delimeter (in this case "@").
In this example the task was to get the domain names of email addresses of the users but there's also an example of how to get the part of the email before the "@" symbol just in case.
more...
In this example the task was to get the domain names of email addresses of the users but there's also an example of how to get the part of the email before the "@" symbol just in case.
Export MySQL query result to CSV
This is just a simple example of how to save the result of MySQL query into CSV file.
At the bottom of the post there's an example for the opposite process - import from a CSV file.
more...
At the bottom of the post there's an example for the opposite process - import from a CSV file.
Count status until it changes
If you need to count events of given type until it changes the following query may help.
For example failed charges before disabling an account.
more...
For example failed charges before disabling an account.
Procedure to populate table
The procedure below allows you to populate table using number of new records as a parameter.
more...
Database optimisation
A few things to look at when optimising the database errors:
1. UPDATE using LIMIT when WHERE clause contains unique id.
more...
1. UPDATE using LIMIT when WHERE clause contains unique id.
MySQL privileges
Create super user with access from the internal network:
CREATE USER 'sami'@'192.168.%' IDENTIFIED BY 'some-secret-password';
more...
CREATE USER 'sami'@'192.168.%' IDENTIFIED BY 'some-secret-password';
Good practices
Here's a small list of good MySQL practices.
Use SQL_CALC_FOUND_ROWS when you create pagination related scripts:
more...
Use SQL_CALC_FOUND_ROWS when you create pagination related scripts:
Restore Innodb database from files
The post explains how to restore Innodb database from file system.
There are two cases mentioned before and after MySQL v.5.6.
The examples are related to a Debian based system but they can be adapted
more...
There are two cases mentioned before and after MySQL v.5.6.
The examples are related to a Debian based system but they can be adapted