iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
For the normal interactive login, run mysql -u user -p. The client asks for the password without putting it in your shell command. To connect to another machine, add a host and, when needed, a TCP port: mysql -h db.example.com -P 3306 -u user -p. A successful login leaves you at the mysql> prompt, where you can run SQL.
The basic MySQL command-line login
Open a terminal, Command Prompt, or PowerShell window and use:
Free tools Windows power users keep installed
One-click scans. No signup required.
mysql -u user -p
Replace user with the MySQL account name. The lowercase -u (or --user) selects that account. The -p option with no password value tells the client to prompt for the password. Type it when prompted; the characters are not echoed to the screen.
If you want to select a database immediately after logging in, append its name:
#1 Best Overall
- Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
- With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
- Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
- Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
- Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.
mysql -u finley -p db_name
The database argument is optional. When supplied, it becomes the initial default database for that session, so statements such as SELECT * FROM table_name; are evaluated in that database unless you qualify another one.
What you need before connecting
- A MySQL server must be running and reachable through a local or network transport.
- You need a valid MySQL account and its password. The account’s host permissions determine where it may connect from.
- For a remote connection, you need the server’s DNS name or IP address and the TCP port exposed by that server.
- The
mysqlcommand-line client must be installed and available in your shell’s command path, or you must run it from the directory containing the client executable.
A syntactically correct command can still fail if the server is stopped, a firewall blocks the port, the server listens only on a different address, TLS is required, or the account is not permitted from your client host.
Understand each command-line option
| Option | Purpose | Example |
|---|---|---|
-u or --user |
Selects the MySQL account. | -u appuser |
-p or --password |
Prompts interactively for the password when no value follows it. | -p |
-h or --host |
Chooses the server host. | -h db.example.com |
-P or --port |
Chooses the TCP port. The capital P matters. |
-P 3307 |
-S or --socket |
Names a Unix socket file explicitly. | -S /path/to/mysql.sock |
--protocol=TCP |
Forces a TCP connection instead of a local socket. | mysql --protocol=TCP -P 3307 -u user -p |
--protocol=SOCKET |
Requests a Unix-socket transport where supported. | mysql --protocol=SOCKET -u user -p |
--protocol=PIPE |
Requests a Windows named-pipe transport when the server is configured for it. | mysql --protocol=PIPE -u user -p |
--protocol=MEMORY |
Requests shared memory on supported Windows configurations. | mysql --protocol=MEMORY -u user -p |
Options can be written in their long form with two hyphens, or in the short forms shown above. The database name, if present, is a positional argument after the options.
Connect to a local MySQL server
The default local command
For a typical local installation, start with:
mysql -u root -p
Use the account you created rather than root when possible. The command works on Linux and Windows once the server and client are available; the account name and authentication method still come from your installation.
Why localhost may ignore your port
On Unix systems, localhost normally selects a Unix-socket connection. For example:
mysql -h localhost -P 3307 -u user -p
may still try the local socket rather than TCP, so the -P 3307 value does not have the effect you expect. The port option applies to TCP connections; it does not change which socket file a local socket connection uses.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #2
- Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
- Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
- Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
- Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
- Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
Force TCP to the local host
Use the loopback IP address when you need TCP:
mysql -h 127.0.0.1 -P 3307 -u user -p
Alternatively, retain the host name and select the protocol explicitly:
mysql --protocol=TCP -P 3307 -u user -p
These forms are useful when the server listens on a nondefault port, when you are testing firewall rules, or when a socket connection is failing while TCP is available.
Use a specific Unix socket
If the server uses a socket in a nonstandard location, identify that file:
mysql -S /path/to/mysql.sock -u user -p
You can also write --socket=/path/to/mysql.sock. The path must match the socket created by the running server. A connection error that names a different socket path usually means the client and server are using different configuration defaults.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Connect to a remote MySQL server
Specify the remote host with -h and the TCP port with the capital -P:
mysql -h db.example.com -P 3306 -u user -p
Port 3306 is the default for MySQL’s classic TCP protocol. Include -P when the server administrator has configured another port:
Rank #3
- 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
- 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
- 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
- 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
- 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
mysql -h 203.0.113.25 -P 3307 -u reporting -p analytics
This example connects to the account reporting, prompts for its password, and selects analytics as the initial database. Replace the example address, port, account, and database with values supplied for your environment.
A remote command requires more than a reachable IP address. The server must listen for remote connections on an address that accepts your client, the network path and firewall must allow the selected port, and the MySQL account must be authorized for your source host. Some environments also require encrypted connections or additional client options; those requirements are specific to the server’s configuration.
Enter the password safely
Use the interactive prompt
Prefer:
mysql -u user -p
After you press Enter, the client displays a password prompt. Input is hidden, which prevents someone looking at the terminal from reading it and avoids placing the secret in the command text.
Why not to put the password in the command
Do not use a real password inline, such as:
mysql -u user -psecret
MySQL documentation describes command-line passwords as insecure because arguments can be exposed through shell history, process listings, job logs, or other users’ diagnostic tools. The prompt form avoids those exposures in normal use.
Noninteractive jobs
Automation sometimes needs credentials without an interactive prompt. MySQL documents protected option files and login-path files for this purpose. Store credentials with operating-system permissions that restrict access, avoid committing them to source control, and ensure that CI logs do not print the resulting command or secret. Choose the mechanism that your deployment’s security policy supports rather than embedding a password in a script’s argument list.
Transport choices by platform
| Situation | Typical command form | Transport behavior |
|---|---|---|
| Unix local default | mysql -u user -p |
Usually uses the local Unix socket. |
| Unix local TCP | mysql -h 127.0.0.1 -P 3306 -u user -p |
Uses TCP and the specified port. |
| Remote server | mysql -h db.example.com -P 3306 -u user -p |
Uses TCP to the named host and port. |
| Explicit Unix socket | mysql -S /path/to/mysql.sock -u user -p |
Uses the named socket file. |
| Windows named pipe | mysql --protocol=PIPE -u user -p |
Uses a named pipe only when the server and client are configured for it. |
| Windows shared memory | mysql --protocol=MEMORY -u user -p |
Uses shared memory on supported configurations. |
The applicable default depends on the operating system, host value, and client/server configuration. Selecting a protocol explicitly is the reliable way to test a particular transport.
Rank #4
- 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
- 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
- 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
- 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
- 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
Windows command-line details
On Windows, you can run the client from the MySQL installation’s bin directory or use the MySQL Command Line Client shortcut supplied with the installation. If mysql is reported as an unknown command from another directory, either change to the directory containing the executable or add that directory to the system or user PATH. The connection syntax itself remains the same:
mysql -u user -p
Windows installations may support named pipes or shared memory in addition to TCP. Those transports require corresponding server settings; selecting --protocol=PIPE or --protocol=MEMORY cannot enable a transport that the server has not configured.
Verify the session and run SQL
- Run your connection command and enter the password at the prompt.
- Confirm that the client displays
mysql>. This prompt means the interactive client is ready to accept SQL or client commands. - Type a SQL statement and terminate it with a semicolon, for example
SELECT DATABASE();. MySQL also accepts\gas a statement terminator. - Continue entering statements. If you supplied a database name on the command line, it is the initial default; otherwise select one with
USE database_name;when your account has permission. - End the session with
QUIT;or\q. On Unix, pressing Control-D also disconnects.
A semicolon is required to execute a multi-line SQL statement. If the prompt changes while you are typing, the client is waiting for the rest of an unfinished statement; complete it with the appropriate closing syntax and terminator.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot a failed connection
“mysql: command not found” or an unknown command
The client executable is not in the shell’s search path. Run it from the installation’s bin directory, use its full path, or add that directory to PATH. This is a client-side lookup problem, so changing the host, port, or password will not fix it.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errors“Access denied for user”
The server was reached, but authentication or account authorization failed. Check the account spelling, enter the password again, and verify that the account is permitted from the host you are connecting from. A user allowed from the local machine may be rejected from a remote address even when the password is correct. If the server uses an authentication plugin or requires TLS, use the connection settings specified by its administrator.
“Can’t connect to local MySQL server through socket”
This usually indicates that the client tried a Unix socket that does not exist, is not the server’s socket, or belongs to a server that is not running. Confirm the server’s configured socket path and retry with -S /path/to/mysql.sock. If the server is listening on TCP instead, bypass socket selection with -h 127.0.0.1 -P port or --protocol=TCP.
Best Value
- 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
- 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
- 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
- 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
- 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
“Connection refused”
The target host was reached but no service accepted the TCP connection on that port. Verify the port number, confirm that the MySQL server is running and listening on that port, and check local or network firewall rules. For a local test, compare localhost with 127.0.0.1 so that you know whether you are testing a socket or TCP.
Timeouts or unreachable host errors
A timeout commonly points to routing, firewall filtering, an incorrect DNS name or address, or a server that is not exposed to your network. Confirm the host and port with the server administrator. Do not assume that a server’s public address implies that MySQL is intentionally open to the public internet.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The command reaches the server but selects the wrong database
A database name on the command line only sets the initial default database; it does not grant access. Check the spelling and permissions, then run USE database_name; after login if you need to change databases. If the named database does not exist or your account cannot use it, authentication can succeed while the database selection fails.
TLS or encryption errors
Some servers require encrypted connections or reject unencrypted clients. The basic login syntax does not by itself establish every possible TLS policy. Obtain the server’s required certificate, verification, and client options from its administrator or hosting documentation, then add those options to the same host, port, user, and password command. Avoid disabling certificate verification merely to make a test connect.
Choose the right command quickly
- Local server, normal Unix setup:
mysql -u user -p - Local server over TCP:
mysql -h 127.0.0.1 -P 3306 -u user -p - Local server with a known socket:
mysql -S /path/to/mysql.sock -u user -p - Remote server on the standard port:
mysql -h db.example.com -P 3306 -u user -p - Remote server on a custom port:
mysql -h db.example.com -P 3307 -u user -p - Login and select a database immediately:
mysql -h db.example.com -P 3306 -u user -p db_name
In every case, keep -p without a value when you want the password prompt. Change the host, port, socket, account, and database only to match the server you are authorized to use.
Quick Recap
Key distinctions to remember
localhoston Unix normally means a Unix socket, while127.0.0.1forces a TCP loopback connection.-Pselects a TCP port; it does not select a Unix socket file.- The classic MySQL TCP port defaults to
3306, but installations can be configured differently. - The
mysql>prompt confirms that the interactive client is ready; it does not by itself prove that every database or statement is authorized. - Use the password prompt or a protected credentials mechanism rather than exposing a password in command-line arguments.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →

