mysql

mysql connects to MySQL or MariaDB, inspects schema and rows, makes focused changes, exports tables, runs native SQL and creates SQL dumps.

DatabaseVersion 1.1.3StableAliases: mariadb
lil-terminal

Overview

Use mysql for both MySQL and MariaDB: passwords stay out of command history, common schema and row tasks have short flags, and native SQL remains available after :.

Tables, rows and native SQL

MySQL and MariaDB are client-server relational databases. Think in databases, tables, rows, columns, indexes and transactions: the table schema constrains the shape of data, while SQL describes sets of rows rather than a sequence of file edits. The mysql driver serves both MySQL and MariaDB; advanced engine-specific SQL remains available after :.

Syntax

lil-terminal
mysql [options] · mysql : <sql>

Reference

mysql

show the current MySQL / MariaDB connection

mysql -c <host> <user> [database] [-p <port>] [-s <socket>] [-charset <charset>] [-n] [-m [name]]

connect; password is requested separately unless -n is used

-use <database>

select another database

-l

list databases

-t

list tables and views

-s <table>

show columns and data types

-n <table> [rows]

preview table rows

-f <table> <text> [rows]

find text across table columns

-o <table> [-j|-csv] [file] [-f]

export table rows

-a <table> : <json>

insert one row from a JSON object

-w <table> <field> <value> : <json>

update matching rows from a JSON object

-d <table> <field> <value>

delete matching rows

-m [name]

save the current connection in .lil.key; default name is the database

-M <name>

remove a saved connection

-k [name]

list saved connections or inspect one without showing its password

-K <name>

connect using a saved connection

-e

disconnect and clear connection data

mysql : <sql>

execute native SQL

mysql load <file.sql>

execute SQL from a file

mysql dump [file.sql] [-f]

create a schema and data dump

mariadb [options]

alias for @mysql

Inspection

-l lists databases, -t lists tables/views, -s shows column definitions, -n previews rows and -f searches text across a table. -o exports one table as JSON or CSV.

Editing

-a inserts a row from a JSON object. -w updates rows matching one field/value pair. -d deletes rows matching one field/value pair. For complex changes use native SQL after :.

Dump and restore

dump creates a SQL schema/data backup without shell tools. load executes an SQL file. Large backups are written directly to disk rather than passed through terminal output redirection.

Connection

-c accepts host, user and optional database. The password is requested separately. -n explicitly requests a passwordless connection. -p changes the TCP port, -s selects a socket and -charset changes the connection charset.

Safety

mysql can execute arbitrary SQL. Use a restricted database account and inspect destructive statements before execution.

-charset selects the connection charset. Table export refuses more than 100000 rows instead of writing a partial file.

Saved connections

Without -m, connection data remains scoped to the current PHP session. -m [name] explicitly stores the current profile in the protected .lil.key file (0600), -K <name> reconnects from it, -k lists or inspects profiles without exposing a stored password, and -M <name> removes one. kill removes .lil.key together with the other core state. Treat the file as sensitive because an opted-in profile can contain database credentials.

Interactive sandbox preview

Run the prepared examples directly on the page. Their results are prebuilt and shown in the browser; no terminal command is executed on the server.

Inspect a MySQL / MariaDB table

Install and manage

Install the current compatible version. Choose Base for the complete feature set or Minimum for the reduced package; use upgrade to update a module that is already installed.

Base and Minimum are two packages of the same current module release, not separate command versions.

Base package

Install the complete package with local command reference and every published mode.

install mysql
Minimum package

Install the reduced package. Local reference is omitted; help <cmd> -i opens the current server reference.

install mysql -m
Exact public version

Install exactly this published version.

install mysql -v 1.1.3
Check or update

Ask upgrade to check compatibility and replace the installed block only when needed.

upgrade mysql
Remove module

Remove the extension block while leaving the core and unrelated modules intact.

install mysql -u

Examples

Examples are copyable command lines, not actions executed by this website. Review paths, permissions and destructive flags before running them on a real project.

Inspect a MySQL / MariaDB table
mysql -use shop | mysql -t | mysql -n products 5
Database  shop

products
orders

id	sku	name	category	price	active
1	SHOE-1	City shoe	shoes	79.90	1
2	SHOE-2	Trail shoe	shoes	109.00	1
3	BAG-1	Canvas bag	bags	44.50	1
Mysql · localhost
mysql -c localhost app shop
Status    connected
Server    MySQL / MariaDB
Host      localhost:3306
User      app
Database  shop
Charset   utf8mb4
Mysql · -l
mysql -l
information_schema
shop
Mysql · products
mysql -s products
Field     Type          Null  Key
id        bigint        NO    PRI
sku       varchar(64)   NO    UNI
name      varchar(180)  NO
category  varchar(80)   NO
price     decimal(10,2) NO
active    tinyint(1)    NO
Mysql · products
mysql -f products "shoe" 20
id	sku	name	category	price
1	SHOE-1	City shoe	shoes	79.90
2	SHOE-2	Trail shoe	shoes	109.00
Mysql · products
mysql -o products -j products.json
Saved  products.json
Mysql · products
mysql -a products : {"sku":"BAG-1","name":"Travel bag","price":49.90}
Inserted  1
Mysql · products
mysql -w products sku BAG-1 : {"price":44.90}
Updated  1
Mysql · products
mysql -d products sku BAG-1
Deleted  1
Mysql · select
mysql : SELECT COUNT(*) AS products FROM products
products
4
Mysql · dump
mysql dump shop.sql
Saved   shop.sql
Tables  2
Views   0
Mysql · load
mysql load \sandbox\db\mysql.sql
Affected  1
Affected  0
Affected  0
Affected  2
Time      2 ms
Mysql · -e
mysql -e
+
Handle a missing table
mysql -s missing_table
Table not found: missing_table

File used in this example: sandbox/db/mysql.sql

The example uses a file or directory from the protected /sandbox/ documentation workspace.

CREATE DATABASE IF NOT EXISTS shop CHARACTER SET utf8mb4;
USE shop;
CREATE TABLE products (id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, sku VARCHAR(64) UNIQUE NOT NULL, name VARCHAR(180) NOT NULL, category VARCHAR(80) NOT NULL, price DECIMAL(10,2) NOT NULL, active TINYINT(1) NOT NULL DEFAULT 1);
INSERT INTO products(sku,name,category,price,active) VALUES ('SHOE-1','City shoe','shoes',79.90,1),('BAG-1','Canvas bag','bags',44.50,1);

Related documentation

Current public release

v1.1.32026-08-14

Saved connections

Adds explicit -m/-M/-k/-K profiles in .lil.key; listings never reveal a stored password.