The quickest way to install a SQL command line client is to install MySQL Shell (for MySQL) or the PostgreSQL command line tools (for PostgreSQL), then add them to your system PATH so you can connect from any terminal. You do not need a full database server running on the same machine: a client alone is enough to connect to a database hosted elsewhere. If you want a single tool that talks to several database types, the MySQL Shell and PostgreSQL tools are each specific to their own database family, so pick the client that matches the server you will actually connect to.
One note before you start: menu labels and installation filenames differ slightly by version, operating system and region, so the names below may vary a little on your machine. The steps below cover Windows, macOS and Linux separately.
What You'll Need
- Administrator rights on your computer (or sudo access on Linux and macOS).
- Your database server's host address or hostname, the port number, and a username and password that can log in remotely. The default ports are 3306 for MySQL and 5432 for PostgreSQL, but yours may have been changed.
- A terminal application. Windows: Command Prompt, PowerShell or Windows Terminal. macOS: Terminal. Linux: any shell, such as bash.
- A stable internet connection to download the installer, or the package already saved locally.
- Confirmation of which database you are connecting to, since the client must match the server family.
Step-by-Step
Identify your database server. If your server is MySQL or MariaDB, use the MySQL client tools. If it is PostgreSQL, use the PostgreSQL tools. A MySQL client cannot connect to a PostgreSQL server and vice versa. If your organisation runs the server, ask which product and version it uses before downloading anything.
Download from the official source. For MySQL, go to the official MySQL downloads page and get MySQL Shell or the MySQL Community Server package that includes the command line client. For PostgreSQL, go to the official PostgreSQL downloads page and get the installer or the command line package. Avoid third-party mirrors and bundle sites; only official downloads guarantee the client matches your server.
Install on Windows. Run the downloaded
.msiinstaller, accept the licence, and choose either the full option or the custom option. If you only want the client, pick Custom and select the client component, for example MySQL Shell or the command line tools. Leave the checkbox that adds the tools to your PATH ticked, because that is what lets you run the client by name from any folder. Finish the wizard.Install on macOS. Using the official installer is simplest: open the
.dmgand follow the prompts, which place the binaries in a system directory. If you use Homebrew, install the package for your database family from the command line, which also handles PATH setup for you. Confirm the binary location the installer reports so you know where it lives.Install on Linux. Most distributions include the client in their package repositories. For Debian and Ubuntu, install the client package with apt; for Fedora and similar, use dnf. This installs only the client-side tools, which is usually what you want on a workstation. Type the
--versionflag after installing to confirm it works.Open a new terminal window. PATH changes made by an installer do not apply to terminals that were already open. Close every existing terminal and open a fresh one so the operating system picks up the new path.
Check that the client is found. On Windows, run
mysql --versionorpsql --versiondepending on the family you installed. The client should print its name and version. On macOS and Linux the same commands work. If the shell says the command is not found, the PATH step is the likely cause; see the troubleshooting section below.Connect to the server. Start the client with your host, port, username and password. For MySQL, the command line is
mysql -h hostname -P 3306 -u username -p, which prompts for the password rather than showing it in the command. For PostgreSQL, usepsql -h hostname -p 5432 -U username -d databasename. Substitute your own host, port and username.Confirm the connection. Once connected, run a harmless query such as the version check query the client provides; in MySQL,
SELECT VERSION();works, and in psql, a bareSELECT version();works. A result means you are in.Exit cleanly. Type
quitor\qto close MySQL, and\qto leave psql. Closing the terminal window abruptly is not harmful, but it can leave an open connection until the server times it out.
Common Mistakes
- Installing the server when you only needed the client. A full server install adds a background service and consumes resources. On a workstation that only needs to connect out, choose the client or custom component only.
- Skipping the PATH checkbox. This is the most common reason the client runs from its install folder but not from any other terminal.
- Testing in an old terminal window. The installer's PATH update is invisible until you open a new window.
- Mixing up the port flag. MySQL uses a capital
-Pfor the port, while a lowercase-pmeans "prompt for password". Using the wrong case produces confusing errors. - Leaving the password on the command line. Typing the password inline leaves it in your shell history. Use the prompt form, or a protected configuration file.
- Trying to connect from the wrong network. A client that installs correctly can still fail if the server's firewall does not allow your address, or if the account is not permitted to connect from your host.
Tips
- Store connection details in a client configuration file in your home directory, such as the MySQL option file or the PostgreSQL service file, with restricted permissions so other users cannot read it.
- Keep the client and server versions reasonably close. A client that is much older than the server can fail to authenticate properly.
- In psql, use the backslash commands such as
\lto list databases and\dtto list tables; they save a lot of typing. - On shared machines, never save an administrative account's password in a globally readable file. Use a personal account with only the privileges you need.
- If you connect to production systems, set the client to show a warning prompt so you do not run a destructive statement on the wrong database.
Troubleshooting
Start with the simplest checks, then work outward from the client to the network.
- "Command not found" or "not recognised". Open a new terminal first. If it still fails, check the PATH variable and confirm the client's folder is listed. Reinstall and pay attention to the PATH option if you cannot find it.
- Access denied for user. The client is working; the credentials or host permissions are not. Confirm the username, that the account exists, and that it is allowed to connect from your machine's address rather than only from localhost.
- Cannot connect to the server or connection timed out. Check the host address and port, then check whether a firewall between you and the server is blocking the port. Ask the administrator to confirm the server is running and reachable.
- Authentication method not supported. This usually means client and server versions are far apart. Install the current client release for your server.
- Installation errors. Restart the computer, make sure no other copy of the client is running, and reinstall using the official installer.
If that did not work, uninstall the client completely and reinstall from the official download, then confirm the version. If you are connecting to a managed database you do not control, contact whoever administers it before changing anything else.
Frequently Asked Questions
Do I need the database server installed to use a command line client?
No. A client only needs network access to a server and valid credentials. You can install the client on a laptop and connect to a database running on another machine.
Can one client connect to both MySQL and PostgreSQL?
Not with the standard command line clients. Each speaks its own protocol. You need the client that matches the server family, and you can install both side by side if you work with both.
Is it safe to put the password in the connection command?
It works, but it leaves the password in your shell history and can expose it to other users on the system. Use the interactive password prompt or a permission-restricted configuration file instead.
How do I know which port to use?
Use the port your server listens on. The defaults are 3306 for MySQL and 5432 for PostgreSQL, but administrators often change them, so confirm with whoever runs the server.
Why does the client work in one folder but not another?
That pattern points at PATH. The folder you are in contains the executable, or the client was installed without its directory being added to the system PATH.
Can I install the client without administrator rights?
Sometimes. On Linux you can unpack a client to your home directory, and on Windows or macOS a ZIP or tarball download may work without a system-wide install. The limitation is that you must add the folder to PATH yourself.