How to connect MySQL from the windows command line
This tutorial is on How to connect MySQL from the Windows command line. MySQL is a popular and open-source relational database application. We guide walks you through using the windows command line(cmd) to connect to a MySQL database. In most cases, we are using localhost/phpmyadmin, but in some cases to get errors and do not open phpmyadmin, so we can use the windows command line.
Open a windows command prompt
First, open the Run command box in Windows. Use the keyboard shortcut – ( Window + R ). Then, type in cmd and press Enter.
Press enter you can see black command line interface should launch.
Check MySQL is Running on Windows
Run the command to display a list of all MySQL services that are currently running.
net start
Connect to MySQL Server
Go to xampp/mysql/bin folder and run the following command:
D:\xampp\mysql\bin> mysql.exe –u<username> –p
Note: Replace with the username for your MySQL username.
Enter mysql.exe –uroot –p
, MySQL will launch using the root user and ask password then Enter a password.
Show databases
Now you can show all databases in your phpmyadmin. run the following command:
show databases;
Use database
We can use database example devnote so run the following command:
use devnote;
Now show all tables using currently use databases(devnote).
show tables;
Select query
The SELECT statement is used to select data from a database.
select * from wp_users;