Refresh MySQL views?

24,297

Solution 1

Views do not need to be refreshed when the data changes. When you query them they will fetch the newest data.

They might need to be recreated if your table structure changes:

The view definition is “frozen” at creation time, so changes to the underlying tables afterward do not affect the view definition. For example, if a view is defined as SELECT * on a table, new columns added to the table later do not become part of the view.

Source

Solution 2

I was working on a project and my view didn't show new data because I was trying to make a join on a NULL field to another table. So I just updated the new data with a correct value for that field and it worked.

Share:
24,297
William W
Author by

William W

I'm just this guy, you know?

Updated on May 31, 2020

Comments

  • William W
    William W almost 4 years

    At work I'm constantly being told that when changes are made to a MySQL db that the views need to be 'refreshed'. The accepted manual solution seems to be going into Workbench, right clicking, and hitting 'Refresh All'

    Is this just meant to be clearing the cache? Or does that rebuild the views from scratch, or is this totally bogus? They seem to be able to tell when views have not been 'refreshed', and I'm not sure they understand it any more than, "Because things need to be refreshed when they are changed."

    If it is just clearing the cache, would 'FLUSH TABLES WITH READ LOCK' be enough?