mysql
command-line client
TLDR
Connect to database
$ mysql -u [username] -p [database]
Connect to remote hostcopy
$ mysql -h [hostname] -u [username] -p [database]
Execute SQL commandcopy
$ mysql -u [user] -p -e "[SELECT * FROM table]" [database]
Execute SQL filecopy
$ mysql -u [user] -p [database] < [script.sql]
Connect with specific portcopy
$ mysql -h [host] -P [3306] -u [user] -p
Import database dumpcopy
$ mysql -u [user] -p [database] < [dump.sql]
copy
SYNOPSIS
mysql [options] [database]
DESCRIPTION
mysql is the MySQL command-line client. It connects to MySQL/MariaDB servers.The tool executes SQL queries. Provides interactive and batch modes.
PARAMETERS
DATABASE
Database name.-h HOST
Server hostname.-u USER
Username.-p [PASSWORD]
Password (prompts if empty).-P PORT
Port number.-e COMMAND
Execute SQL and exit.--help
Display help information.
CAVEATS
Requires server access. Password prompt recommended. Beware SQL injection in scripts.
HISTORY
mysql was created as the standard CLI for MySQL database, maintained by Oracle and the community.