How to Query a List in MySQL
This post will discuss the easiest way to query a list in MySQL.
How to Query a List in MySQL?
Follow the below-provided instructions to query a list in MySQL:
- Open the Windows terminal.
- Connect with a particular MySQL database by providing its username and password.
- Display all existing databases and choose the desired one.
- Change the database and use the “SELECT <column-name> FROM <table-name>” command to list particular table column data.
Step 1: Launch “Command Prompt”
Initially, open the Windows terminal by utilizing the Startup menu:
Step 2: Connect MySQL Database
Then, execute the provided command to log in with your MySQL server to start the services locally and connect with the terminal:
Here:
- “-u” option represents the user.
- “root” is the default username specified while installing MySQL.
- “-p” option denotes the password.
When above stated command is executed, you will be asked to provide the user password:
Step 3: View All Databases
Next, to display the list of all currently existing databases, execute the “SHOW” command with the “DATABASES” option:
As you can see, all databases are listed, and we have selected the “mariadb” database for further process:
Step 4: Change Database
Now, run the “USE <database-name>” command and navigate to the desired database:
Step 5: Query List in MySQL
Finally, execute the “SELECT Color FROM mariadb” query to view the list of data in MySQL:
In the above-stated query:
- “SELECT” statement is used to select the data from the available databases.
- “Color” is the column name that contains data.
- “FROM” clause is utilized for selecting desired records from existing tables of the database.
- “mariadb” is the name of our table that is created inside our database:
It can be observed that when the above-provided query is executed, the data inside the “Color” column is listed below:
That’s it! We have compiled the easiest way to query a list in MySQL.
Conclusion
To query a list in MySQL, first, open the Windows terminal and connect with your MySQL database by providing a username and password. Then, list all existing databases and choose the desired one. Next, move to it and execute the “SELECT <column-name> FROM <table-name>” query to list particular table column data. This post demonstrated the method to query a list in MySQL.
Source: linuxhint.com