Start using MySQL

Connect with the mysql client

Open an administrative command-line session, keep passwords out of shell history, and verify the server and matched account.

The mysql command-line client is the tool this course uses for everything administrative. Graphical tools are fine for browsing, but the client shows you exactly what the server said, and every command in it is copy-pasteable into scripts and documentation.

If the administrative account has a password, ask the client to prompt for it:

$(brew --prefix [email protected])/bin/mysql -u root -p

Do not put the password after -p. That can expose it in shell history and process lists. With a bare -p, the client prompts for the password and nothing sensitive touches the command line.

A fresh local Homebrew installation may initially use mysql -u root without -p. Follow the installation output, then secure the account before allowing network access.

When the connection succeeds you land in an interactive session:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.4.8 Homebrew

mysql>

Statements end with a semicolon. Press Enter without one and the client shows a continuation prompt, waiting for the rest of the statement.

Verify the server after connecting:

SELECT VERSION();
SELECT CURRENT_USER();

CURRENT_USER() shows the full MySQL account that matched the connection, including the host part. That matters because the account you asked for and the account that matched can differ, and grants attach to the matched account. Leave the client with QUIT;.

When the login fails

The most common failure looks like this:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Read it carefully before retyping anything. It tells you which account MySQL tried ('root'@'localhost') and whether a password was sent (using password: YES). A wrong password, a missing account, and an account created for a different host all produce this same error, so the account name in the message is your first clue.

Lesson completed

Take this course offline

Get every free book, course edition, and software download.

Get the download library →