MySQL 8.4 cheatsheet

MySQL 8.4: Connecting

6 common MySQL 8.4 tasks.

Check the client version

Print the version of the mysql client.

mysql --version

Connect to a server

Open the mysql client as a user, prompting for the password.

mysql -u root -p

Connect to a specific host and database

Open the client on a given host, port and database.

mysql -h 127.0.0.1 -P 3306 -u root -p mydb

Check the server version

Run inside the client to see the server version.

SELECT VERSION();

Run a SQL file

Execute the statements in a file against a database.

mysql -u root -p mydb < script.sql

Quit the client

Leave the mysql prompt and return to the shell.

exit

Was this page helpful?