Skip to content

MySQL

Commands

Run as a Docker container

docker run --name mysql -p 3306:3306 -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8

Connection

mysql -u username -p password -h hostname

SQL

Getting primary key from table

SHOW KEYS FROM TABLE;

Check the process

SHOW PROCESSLIST;

Check the max_connections

SHOW VARIABLES LIKE 'max_connections';

output:

+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 150   |
+-----------------+-------+

Checking the wait_timeout

SHOW VARIABLES LIKE '%timeout%';

To show the comments from the table

SHOW FULL COLUMNS FROM TABLE;

Explain the SQL statement

EXPLAIN SELECT * FROM table WHERE condition;

JSON

JSON_ARRAY will return a JSON array

mysql> SELECT JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME());
+---------------------------------------------+
| JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME()) |
+---------------------------------------------+
| [1, "abc", null, true, "11:30:24.000000"]   |
+---------------------------------------------+

Troubleshooting

MySQL ERROR 1227 (42000) at line 18: Access denied; you need (at least one of) the SUPER privilege(s) for this operation

mysqldump --skip-lock-tables --set-gtid-purged=OFF ......
Back to top