Search notes:

MySQL

use mysql;
show tables;
select * from mysql.user;
select * from mysql.db;
select
  user(),
  current_user(), -- the account that the server used to authenticate a user
  session_user(),
  system_user()
set global innodb_file_per_table=1;
If the innodb_file_per_table option is set, a table can be (or is?) created in its own *.ibd* file rather than in a shared ibdata file of the system tablespace.
This option is enabled by default.
An instance is a mysqld daemon in Unix or a service in Windows. The instance listens on its designated TCP port (the default being 3306).
An instance manages a data directory (that in turn consists of one ore more databases).
The default name for the Windows instance service when installing MySQL 8 is MySQL80.
The mybinsqllog command examines the content of bin logs (binary log files).
MySQL's equivalent of Oracle's index-organized tables are clustered indexes.
A database is the same thing as a schema (both words are used synonously.
The data directory is the directory under which an instance stores data files for InnoDB.
Do data directories contain a sub-directory for each database?
Compare the datadir configuration option.

Starting the MySQL daemon / service

On Windows, the MySQL service can be started with mysqld.exe

Starting MySQL client

Apparently, there must be no space between the -p option and the password.
mysql -u rene -psecretGarden
mysql -u rene -psecretGarden --local-infile
mysql -u rene -psecretGarden tq84_db
mysql -u rene -psecretGarden tq84_db < script.sql

User accounts

An account name consists of a user name and a host name. The syntax to specify an account name is 'rene'@'host.xyz'.
'rene'@'%' is equvalent to 'rene`.
create user rene@localhost identified by 'rene';
create user rene@'%'       identified by 'rene';
grant all on tq84_db.* to rene@localhost;
grant all on tq84_db.* to rene@'%';
grant all on       *.* to …
Special (reserved) accounts are:

Engines

show engines;
select * from information_schema.engines;
select @@default_storage_engine;
The default storage engine in MySQL 8 is InnoDB.

InnoDB

InnoDB is a multi-versioned storage engine.
select * from information_schema.innodb_tables where name = 'ts/tab';

SQL modes

show variables like 'sql_mode';

select @@global.sql_mode;
select @@session.sql_mode;
set session sql_mode = '…';
set global  sql_mode = '…';

information_schema

select
   tab.table_name      ,
   tab.table_catalog   ,  -- always def?
   tab.table_type         -- always SYSTEM VIEW
from
   information_schema.tables tab
where
   tab.table_schema = 'information_schema';
The following tables might be returned:

Determining MySQL version

select * from sys.version;
select version();
show variables like "%version%";
See also determine database versions

Tables

create table tab (a integer) engine = myIsam;
Show structure of table:
show create table tab;
show columns from tab;
select * from information_schema.columns where table_name = 'tab' and table_schema = '…';

Databases

create database tq84_db
  [ [default] character set … ]
  [ [default] collate       … ] -- NOTE to self: the keyword is collate, not collation!
show databases;
select database();

Transactions

Apparently, auto commit is enabled by default.
It can be turned off (for a session):
set autocommit = false;
Transactions are started with one of
begin;
begin work;
start transaction;
show        variables like 'autocommit';
show global variables like 'autocommit';

Sessions

show processlist
The id of the process is retrieved by show processlist.
kill 20 

Importing CSV files

set global local_infile = on;

show variables like 'local_infile';
show variables like 'secure_file_priv';
The default location that secure_file_priv points to is %ALLUSERSPROFILE%\MySQL\MySQL Server X.Y\Uploads.
The local_infile option controls if the server permits local data loading (load data local).
load data statements without character set clause default to using the value of the character_set_database system varible.
Start mysql with the --local-infile option
mysql -u rene -prene --local-infile tq84_db

Character sets and collations

The reportoire of a character set is the collection of characters in the set.
MySQL Server has a server character set and a server collation which are set at startup (options --character-set-server=… and --collation-server=…).
Similarly, a database has a database character set and a database collation.
Similarly, every character string has a character set and a collation
System variables character_set_database, character_set_connection, collation_connection.
utf8 is an alias for the utf8mb3 character set and stores a maximum of three bytes per character. It allows to represent the code points 0x0000 through 0xffff, thus, it cannot store all Unicode characters. utf8mb3 is deprecated and will be removed in a future version of MySQL, probably in favor of utf8mb4.
utf8mb4 is what most of the world would call utf-8. It uses up to four bytes per character and thus allows to store supplemental characters (such as emoji).
show character set;
show character set like 'utf8%'
show collation where charset = 'utf8mb4';

select * from information_schema.character_sets order by character_set_name;

select * from information_schema.collations where character_set_name = 'utf8mb4' order by collation_name;
select
  @@character_set_database,
  @@collation_database;
select
   default_character_set_name,
   default_collation_Name
from
   information_schema.schemata
where
   schema_name = 'tq84_db';
create table tab (
   col_1 varchar(50) character set ascii,
   col_2 varchar(50) character set latin1
);
In the following example, _utf8 and _ucs2 are called introducers.
select
  _utf8'foo'    collate …,
  _ucs2 X'0041' collate …
show variables like 'character_set_system';
Collation suffixes:

set names

set names specifies the character set of the communication between the server and the client.
set names ascii;
set names utf8;
set names cp1251;

Show variables with character set in their names

show variables like '%character%';

Variable_name                                                    Value                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
---------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
character_set_client                                             utf8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
character_set_connection                                         utf8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
character_set_database                                           utf8mb4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
character_set_filesystem                                         binary                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
character_set_results                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
character_set_server                                             utf8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
character_set_system                                             utf8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
character_sets_dir                                               C:\Program Files\MySQL\MySQL Server 8.0\share\charsets\                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

8 rows selected. 

National character set

nvarchar(10) character set utf8 = national varchar(10) == nvarchar(10) == nchar varchar(10) == national character varying(10) == national char varying(10).
char(10) character set utf8 == national character(10) == nchar(10).
N'foo bar' == n'foo bar' == _utf8'foo bar'.
create database db_xyz
       character set utf8mb4
       collate       utf8mb4_0900_as_cs  -- Accent and case sensitive.
;

System variables

show variables;
show variables like '%some_text%';
Changing (global?) system variables. However, it does not seem to survive a bounce.
set global local_infile = on;

Security

Is mysql -u root possible?
show grants;
show grants for 'rene'@'somewhere.net';
The secure_file_priv system variable.
The user option under [mysqld] in the configuration file.

Installation

In order to change the installation path when installing on Windows, MySQL in their finite wisdom has chosen to let a user do that by clicking an inconspicuous* link named «advanced option».

datadir

The location of the datadir can be found with
select @@datadir;
On Windows, the default directory for the datadir seems to be %ProgramData%\MySQL\MySQL Server x.y\Data.

Comments

select * from tab; -- comment
select * from tab; #  Anothter comment
select * from tab; /* c like comments */
If using --, a subsequent space or tab or newline is required to recognize it as comment.
A special variant is /*! mysql feature */: it passes mysql feature to the sql engine but other databases will parse this as comment.
See also comments in the SQL standard.

Casting between datatypes

cast(val as dataType)
dataType is one of

Timing / profiling / monitoring

show variables like 'performance_schema';
select * from information_schema.engines where engine       = 'PERFORMANCE_SCHEMA';

-- Note the lower case table schema and lower case table names:
select * from information_schema.tables  where table_schema = 'performance_schema';
Configure and show *monitoring characteristics with setup tables:
select * from performance_schema.setup_actors;
select * from performance_schema.setup_consumers;
select * from performance_schema.setup_instruments;
select * from performance_schema.setup_objects;
select * from performance_schema.setup_threads;

update performance_schema.setup_… set enabled = 'NO' where name = '…';
select * from performance_schema.events_waits_history where thread_id = 13 order by event_id;
select * from performance_schema.events_waits_summary_global_by_event_name;

Processes

The processlist seems to show connected users and what SQL statement they're currently executing (column info):
show processlist;
select * from information_schema.processlist;

select
   id,
   user,
   db,
   time,
   state,
   info   as sql_stmt
from
   information_schema.processlist
where
   command = 'Query';

Parallel execution

show variables like '%innodb_parallel_read_threads%';
set local innodb_parallel_read_threads=32;

Spatial data

An SRSID identifies a spatial reference system.
select
   srs_id,
   srs_name,
   organization,
   organization_coordsys_id,
   definition,
   description
from
   information_schema.st_spatial_reference_systems;

select * from information_schema.st_spatial_reference_systems where srs_id in (
   0   , --                          (cartesian projection)
   4326, -- WGS 84                   (= GPS coordinates)
   3857  -- WGS 84 / Pseudo-Mercator (map projection used on Google Maps, OpenStreetMap etc., but not in paper maps) 
);

TODO

Is autocommit set? How is it turned off?
What does the following do?
show warnings;

See also

%ALLUSERSPROFILE%\MySQL\MySQL Server X.Y\my.ini
Connect to MySQL with Oracle's SQL Developer
The R package RMySQL
MySQL on the command line

Index