Loading half a billion rows into MySQL
Some advice for bulk loading many records into InnoDB and finishing before the sun burns out. Use with care.
Related cards:
SQL: Find out number of rows of all tables within a MySQL database
Here you are:
SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'your_database' order by table_rows;
How to load only a subset of a massive MySQL dump
I had a huge MySQL dump that took forever (as in: days) to import, while I actually just wanted to have the full database structure with some data to use on my development machine.
After trying several suggestions on how to speed up slow MySQL du...
In MySQL, a zero number equals any string
In MySQL comparing zero to a string 0 = "any string"
is always true!
So when you want to compare a string with a value of an integer column, you have to cast your integer value into a string like follows:
SELECT * from posts WHERE CAST(po...
Mysql::Error: BLOB/TEXT column can't have a default value
mysql> SELECT @@global.version;
+------------------+
| @@global.version |
+------------------+
| 5.6.30 |
+------------------+
1 row in set (0,00 sec)
[MySQL 5.6 Reference Manual](https://dev.mysql.com/doc/refman/5.6/en/sql-mode...
PostgreSQL vs MySQL: How to UPDATE using a JOIN
When you want to UPDATE
a table with information from an associated table, you can JOIN
the associated table into the statement.
Example
Let's say you have a database schema where an Employee belongs_to :department
:
+-----...
How to create a user with all privileges to MariaDB
Create a user without password (recommended)
Replace newuser
with your desired username:
mysql -uroot -p
CREATE USER 'newuser'@'localhost' IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
exit;...
MySQL: For each group, retrieve a comma-separated list of values in a given column
The technique described in this card has an important caveat: The result of GROUP_CONCAT
is truncated to the maximum length that is given by the group_concat_max_len
system variable, which has a default value of 1024. **This will cause hor...
Loading dumps via SSH, unpacking and sourcing them, all with a progress bar
Here is a hacky way to load dumps directly from the source server, without fully copying them over and extracting them first.
It [may break horribly for you](https://makandracards.com/makandra/595-dumping-and-importing-from-to-mysql-in-an-utf-8-s...
How to update a MySQL column with ascending numbers
Given the problem you have a new column postion and that column should be updated for all existing rows with ascending numbers. Furthermore these numbers should be generated by a special order. In order to achieve that you could do the fol...