Skip to content

Instantly share code, notes, and snippets.

@dmertl
Last active May 9, 2024 05:47
Show Gist options
  • Save dmertl/a7004c441d2c1e06183caba23bce765d to your computer and use it in GitHub Desktop.
Save dmertl/a7004c441d2c1e06183caba23bce765d to your computer and use it in GitHub Desktop.
MySQL Cheatsheet

Don't print results (null pager)

mysql> pager > /dev/null
PAGER set to '> /dev/null'
mysql> SELECT 1;
1 row in set (0.00 sec)

mysql> pager
Default pager wasn't set, using stdout.
mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

Timezone Conversion

SELECT CONVERT_TZ('2024-05-07 10:36:29', 'UTC', 'America/Los_Angeles');

Check cp-1252 as UTF-8

If you see several weird characters in a row that look like incorrect character encoding there's a good chance it's UTF-8 interpreted as cp-1252. For example, “ in cp-1252 is 0xE2 0x80 0x9C. Those same 3 bytes in UTF-8, 0xE2809C is . In MySQL you can do a quick conversion to check:

mysql> SELECT CONVERT(UNHEX(HEX(CONVERT("“" USING LATIN1))) USING utf8mb4);
+--------------------------------------------------------------------+
| CONVERT(UNHEX(HEX(CONVERT("“" USING LATIN1))) USING utf8mb4)     |
+--------------------------------------------------------------------+
| “                                                                  |
+--------------------------------------------------------------------+

mysql CLI colors

https://github.com/nitso/colour-mysql-console

brew install grc then copy the .grcat and .my.cnf to your home dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment