JIYIK CN >

Current Location:Home > Learning > DATABASE > MySQL >

Searching for occurrences of a string in a MySQL database

Author:JIYIK Last Updated:2025/04/11 Views:

As a database administrator, there are certain situations and circumstances where you have to search the entire database for the occurrence of a pattern or a string.

For example, how many employees use Gmail accounts in your office, or you want to know a certain age from the employee table to know their retirement date, etc.

We will explore a GUI-based approach to searching your entire database, including searching in MySQL Workbench and phpMyAdmin. However, you can also create SQL commands and procedures.

For this article, we'll focus on the GUI options for searching.


Method 1: Search the entire phpMyAdmin数据库

Here, we will see how to search all the tables in the database using phpMyAdmin. You can easily find the occurrences of the required string by following the given steps.

Create database and table

We created a persondatabase named and two tables named studentand .teacher

Fill the table and check the data

You can use the following code to insert data into each table.

#insert into student table
INSERT INTO student(ID, FIRST_NAME, LAST_NAME,GENDER, EMAIL)
VALUES
(1,'Shaajeel', 'Daniel', 'Male','shajeeld@gmail.com'),
(2,'Nayya', 'Preston', 'Female','npreston@yahoo.com'),
(3,'James', 'Robert', 'Male','james@yahoo.com'),
(4,'Jennifer', 'John', 'Female','jennifer09@hotmail.com'),
(5,'Sarah', 'Paul', 'Female','sarahpaul011@yahoo.com'),
(6,'Karen', 'Donald','Female','dkaren@gmail.com');

#insert into teacher table
INSERT INTO teacher(ID, FIRST_NAME, LAST_NAME,GENDER, EMAIL)
VALUES
(1,'Thomas', 'Christopher','Male','thomasC098@hotmail.com'),
(2,'Lisa', 'Mark', 'Female','lisamark@gmail.com'),
(3,'Anthony', 'Richard', 'Male','anthony044@yahoo.com'),
(4,'Matthew', 'Charles', 'Male','matthewcharles@gmail.com')
(5,'Kiren', 'Donald','Female','dkiren@gmail.com');

You can SELECTview the inserted data using the following query.

SELECT * FROM `teacher`;

SELECT * FROM `student`;

Search string

To search for a string,

  • First, select the database (see Box 1).
  • Click 搜索the tab and enter the string, pattern, or expression to search for (see box number 2).
  • You can choose your search criteria whether you are looking for an exact match or something else; see red box number 3.

We are looking for an exact match as a substring for this tutorial. Select the table to search for red box number 4 and click GOthe button at the bottom right.

The following screenshot will show the count of matches found for each table. You can click 浏览the button to view the corresponding full record (row).


Method 2: Search the entireDatabase

If you use MySQL Workbench, you can use the graphical user interface to search the entire database for a specific string or pattern.

First, select all the tables you want to search (see red box 1). Remember, if you don't select the tables, the search will not be performed.

Click Database Menuand select Search Table Data( Database Menu -> Search Table Data). Since we are searching for an exact match of a substring, we selected CONTAINS(see red box number 3), but you can select as needed.

Now you can write the string or expression you want to search for (see red box number 4).

You can know the maximum number of matches for each table and the complete database. You can also specify whether you want to search all types of columns with a single click 开始搜索.

It will display the output including schema, table name, primary key, column name (where the match was found) and its value (see red box number 6).


in conclusion

After learning about two methods of searching the entire database, including searching through MySQL Workbench and phpMyAdmin, we concluded that the GUI option makes life easy for database administrators, database programmers, and architects. Although there are SQL queries behind the scenes, we can use the GUI option to operate more efficiently and faster.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

If ELSE in MySQL

Publish Date:2025/04/11 Views:85 Category:MySQL

In this tutorial, we aim to explore how to use IF ELSE the statement in MySQL. One of the key roles of a data analyst is to gather insights from the data and produce meaningful results. It can be done with the help of several data filtering

DATETIME vs. TIMESTAMP in MySQL

Publish Date:2025/04/11 Views:117 Category:MySQL

DATETIME and TIMESTAMP are two different data types that can be used to store values ​​that must contain both a date and a time portion. In this article, we will understand how it is stored in the database and the memory required for ea

Execute multiple joins in one query in MYSQL

Publish Date:2025/04/11 Views:94 Category:MySQL

Have you ever wondered how to include multiple joins in one query in MySQL? You have come to the right place. Remember that joins allow us to access information from other tables. This information is included separately to avoid redundancy.

Joining 3 tables in MySQL

Publish Date:2025/04/11 Views:187 Category:MySQL

In this tutorial, we will learn how to join three tables in MySQL. Businesses and organizations may have to visualize three tables simultaneously based on certain matching columns common to all three tables. This operation is allowed in MyS

Use of UPDATE JOIN in MySQL

Publish Date:2025/04/11 Views:85 Category:MySQL

This tutorial will explain how to use the statement in MySQL database UPDATE JOIN . We generally use joins to iterate over the rows in a particular table which may or may not have similar rows in other tables. We can UPDATE use JOIN the cla

How to use the Row_Number() function in MySQL

Publish Date:2025/04/11 Views:142 Category:MySQL

In this tutorial, we will explain how to use the VALUES function in MySQL ROW_NUMBER() . This is a sorting method that assigns consecutive numbers within a partition starting from 1. It is important to note that no two rows within a partiti

Multiple primary keys in MySQL

Publish Date:2025/04/11 Views:66 Category:MySQL

In this tutorial, our goal is to explore the concept of multiple primary keys for a table in MySQL. Many times, businesses and organizations have to assign certain columns as primary keys. This primary key has multiple uses and reasons to b

Displaying foreign keys in MySQL

Publish Date:2025/04/11 Views:55 Category:MySQL

In this tutorial, we aim to explore how to display foreign keys for tables and columns in MySQL. The type of key that references a primary key, also known as the primary key of another table, is called a foreign key. Understanding the forei

Select first N rows in MySQL

Publish Date:2025/04/11 Views:85 Category:MySQL

Sometimes, you have to select first N rows of MySQL database according to your project requirements. n The value of varies according to the requirement; it can be TOP 1 row or TOP 30 rows. We will learn how to select top N rows using the cl

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial