I have a database with name test
having two tables
sample1(name, quote)
sample2(name, quote)
I need a replace function or procedure that does the following
- Find columns with String data type (Text,varchar,char,etc) in all tables within
test
database - Look for a value in that column and replace it with a new value
I have found an stored procedure in this post but I don't understand how it works.
is there anyway to achieve this or adopt the stored procedure in the linked post for my use?
-
can you elaborate your questions little bit more in detail. as I can see you have two questions you want to replace something in db and how it is being related to table_schema???MySQL DBA– MySQL DBA2015年07月29日 06:11:55 +00:00Commented Jul 29, 2015 at 6:11
-
with respect to replacing a specific text in entire databases. You can refer to solution provided here :stackoverflow.com/questions/4822638/…MySQL DBA– MySQL DBA2015年07月29日 06:13:45 +00:00Commented Jul 29, 2015 at 6:13
-
Regarding table_scheme I don't know what is this and how I can get it from phpmyadmin. can you write a sample query for it.Developer– Developer2015年07月29日 06:18:33 +00:00Commented Jul 29, 2015 at 6:18
-
table_schema is nothing but your database name. If you query informaiton_schema.tables you get the details.MySQL DBA– MySQL DBA2015年07月29日 06:38:59 +00:00Commented Jul 29, 2015 at 6:38
-
You searched a lot and found `table_schema'? where did you find it? How is it related to the remaining text and the title of your post?miracle173– miracle1732015年07月29日 07:19:41 +00:00Commented Jul 29, 2015 at 7:19
1 Answer 1
MySQL's replace function should come handy to replace the text you need:
update $table set column = replace(column, 'old_text', new_text') where column='old_text' and <other_conditions>;
Now, as you talk of replace in all tables, that's something not possible in single query. Though you can create a routine to do so! For the sample you can refer a procedure which is finding a string in all tables of all databases.
- (Though been already mentioned in comments)
table_schema
is a column name ofinformation_schema.tables
table which represents the database name.