1

I have a database with name test having two tables

  1. sample1(name, quote)
  2. sample2(name, quote)

I need a replace function or procedure that does the following

  1. Find columns with String data type (Text,varchar,char,etc) in all tables within test database
  2. 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?

Evan Carroll
65.7k50 gold badges259 silver badges510 bronze badges
asked Jul 29, 2015 at 5:56
8
  • 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??? Commented 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/… Commented 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. Commented Jul 29, 2015 at 6:18
  • table_schema is nothing but your database name. If you query informaiton_schema.tables you get the details. Commented 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? Commented Jul 29, 2015 at 7:19

1 Answer 1

3

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 of information_schema.tables table which represents the database name.
answered Jul 29, 2015 at 9:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.