Find and replace entire mysql database

后端 未结 12 2141
走了就别回头了
走了就别回头了 2020-11-27 13:16

i would like to do a find and replace inside an entire database not just a table.

How can i alter the script below to work?

 update [table_name] set          


        
12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 13:47

    Short answer: You can't.

    Long answer: You can use the INFORMATION_SCHEMA to get the table definitions and use this to generate the necessary UPDATE statements dynamically. For example you could start with this:

    SELECT TABLE_NAME, COLUMN_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = 'your_schema'
    

    I'd try to avoid doing this though if at all possible.

提交回复
热议问题