How to Access MySQL server from your windows Command prompt, Execute all Queries from the Command Line!

Raymond Havim
3 min readAug 2, 2023

--

Is MySQL Graphical User Interface(GUI)/ MySQL Workbench the only means through which you access and interact with your MySQL server?

NO!

Can I access and interact with MySQL server through my Windows Command Prompt and as well execute all MySQL queries right here just like I do in MySQL Workbench?

Big Yes!

How then can we do this?

Well just like how we are accustomed to using the GUI /MySQL Workbench in all our tasks such as Designing Databases, Granting Access , Retrieving Datasets from the the Database as well as all the others, we are equally able to use the command prompt to perform these very tasks.

Steps to follow to realize these are enumerated below,

  1. To start with, click on your windows start menu and type in “cmd to find and open command prompt and minimize same.
  2. The next thing is to locate your Local Disc — (C:) Local Disk , open it and proceed to open the Program Files folder, open the MySQL folder, next to be opened is MySQL Server 8.0 folder and finally open the bin folder.

(C:) Local Disk ➡️ Program Files ➡️ MySQL ➡️ MySQL Server 8.0 ➡️ bin

3. Now you are to copy the path above clicking the path bar as shown by arrow below . The highlighted in the second image below is the bin file path to copy

click beside bin, where arrow is directing

4. Go back and open your already launched Windows Command prompt and execute the command ;

<cd C:\Program Files\MySQL\MySQL Server 8.0\bin>

Press Enter

where cd means current directory you want to execute command and C:\Program Files\MySQL\MySQL Server 8.0\bin is the bin file path you had copied as highlighted in blue in the second photo above.

5. Finally go ahead and login to your MySQL Local server by executing the command

<mysql -u root -p>

Press Enter , you will be asked to enter your password and vualaa! you have successfully logged in.

Now go ahead and execute all your SQL queries just like you do in the work bench and see results.

NB; Make sure to terminate every query before executing just like you do in the MySQL Workbench.

Scan QR Code to read Article

--

--