Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

way to search entire database for a string in MySQL

Tags:

mysql

I am working on a MySQL database that is huge (about 120 tables). I am trying to make some sense of it and it will help a great deal if I can search all 120 tables + columns for a string I am looking for.

Is that possible to do on a MySQL DB?

like image 598
Omnipresent Avatar asked Sep 05 '09 20:09

Omnipresent


People also ask

What is MySQL full-text search?

Full-Text Search in MySQL server lets users run full-text queries against character-based data in MySQL tables. You must create a full-text index on the table before you run full-text queries on a table. The full-text index can include one or more character-based columns in the table.

How can I see the whole database in MySQL?

Open the Command Prompt and navigate to the bin folder of your MySQL Server installation directory. Then connect to the server using the mysql -u root -p command. Enter the password and execute the SHOW DATABASES; command we have discussed above.

How do I search for a specific data in a SQL database?

SQL Server Management Studio Object Explorer browse to the database you want to search through. write the name (full or partial) of the database object in the Search text box. press Enter to start the search process.


1 Answers

This will help you to find a string in entire database

DELIMITER ##
 CREATE PROCEDURE sp_search1(IN searchstring INT)
BEGIN
 DECLARE done INT DEFAULT FALSE;
 DECLARE output TEXT;
  DECLARE table_name TEXT;
  DECLARE column_name TEXT;
DECLARE s TEXT;  
 DECLARE searchcursor CURSOR FOR 
SELECT table_name,column_name  FROM information_schema.columns AS column    
ORDER BY table_name,ordinal_position;   
OPEN searchcursor;
PREPARE stmt2 FROM 'select * from ? where ? = ?' ;  
search_loop : LOOP
IF done THEN 
LEAVE search_loop;
END IF;              
FETCH searchcursor INTO table_name,column_name;
IF(     EXECUTE stmt2 USING table_name, column_name,searchstring) THEN
 INSERT INTO `table_names`(`table_name`) VALUES(@table_name);    
    END IF;
END LOOP;   
END;
like image 171
Venkat Avatar answered Nov 15 '22 22:11

Venkat