| by Arround The Web | No comments

How to Query a List in MySQL

MySQL is one of the most widely utilized database management systems which is developed by Oracle and based on SQL (Structured Query Language). Moreover, it provides reliability, speed, and usability. To retrieve desired data, sort any data, group, join the tables, filter data, and modify data from the databases, multiple queries are used. Moreover, you can list any particular data through the queries.

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:

mysql -u root -p

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:

SHOW DATABASES;

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:

USE mariadb;

Step 5: Query List in MySQL

Finally, execute the “SELECT Color FROM mariadb” query to view the list of data in MySQL:

SELECT Color FROM mariadb;

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.

Share Button

Source: linuxhint.com

Leave a Reply