MySQL has it’s own terminal emulator, providing a command-line interface (CLI) for the direct input and execution of SQL commands and scripts.

The MySQL terminal emulator can be called from PowerShell, CMD or added to the Windows Terminal.

screenshot of Windows Terminal running a MySQL terminal, with some SQL commands

Starting A MySQL Terminal Session From Inside an Active PowerShell or CMD Session

The MySQL terminal is launched by calling program ‘mysql.exe’. A number of parameters can be passed, the full list is available at 4.5.1.1 mysql Client Options .

The parameters I typically use are detailed below:

ParameterDetails
–portDefault=3306 - TCP/IP port number for connection.
–hostDefault=127.0.0.1 - Host on which MySQL server is located
–local_infile=1Default=0 - Allow importing of data from the local client
–userDefault=root - MySQL user name when connecting to the server.
-pPassword to use when connecting to the server.

Here are examples of calling mysql.exe with these parameters:

PowerShell

1& 'C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe' --port=3306 --host=127.0.0.1 --local_infile=1 --user=root -p

CMD

1"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe" --port=3306 --host=127.0.0.1 --local_infile=1 --user=root -p

Example SQL Commands

 1SHOW databases;
 2USE employeeschema;
 3SHOW TABLES;
 4CREATE TABLE itemType (
 5    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
 6    description VARCHAR(100) NOT NULL,
 7    loanDuration INT NOT NULL,
 8    created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
 9    PRIMARY KEY (id)
10    );
11INSERT INTO itemType(description, loanDuration)
12    VALUES
13    ('Raspberry Pi Kits', 28),
14    ('Raspberry Pi Hats & Microcontrollers', 28),
15    ('Raspberry Pi Books', 56)
16    ;
17SELECT * FROM itemType;

Windows Terminal - Adding A Dedicated MySQL Terminal

  1. Start Windows Terminal

  2. Open Settings Ctrl + ,

  3. Click + Add new (bottom left corner)

  4. Enter the values for your installation, for example:

    • Name: MySQL
    • Command Line: C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe -h localhost -u root -p (yours might be different)
    • Starting directory: I’ve left this empty
      • I’ve ticked “Use parent process directory”
    • Icon: I just used an emoji (press Windows + .). I’m using this one… 🐬
    • Tab Title: MySQL

    Done.