Mysql Command Line Client: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 46: Line 46:
mysql -u root -p<password> -e "SELECT VERSION()"
mysql -u root -p<password> -e "SELECT VERSION()"
</syntaxhighlight>
</syntaxhighlight>
The command sends the result to stdout. If the select query produces no results, the stdout is the empty string.

Revision as of 06:05, 30 March 2021

Internal

Options

-e, --execute=name

Execute command and quit.

Connect

mysql -u root -p

Will challenge for password.

mysql -u root -p<password>

No space after -p.

The username and password can also be stored in ~/.my.cnf:

[client]
user = root
password = XXXXXXXX

Scripting Database Interaction

mysql -u root -p<password> < statements.sql

where statements.sql should contain SQL:

SELECT VERSION();
...

Alternatively:

mysql -u root -p<password> -e "SELECT VERSION()"

The command sends the result to stdout. If the select query produces no results, the stdout is the empty string.