How to check if MySQL query is valid without executing it?

前端 未结 5 2320
小蘑菇
小蘑菇 2021-02-20 06:24

I\'m making a simple tool that will get a string of MySQL commands and run it (on several DB servers sequentially). I trust the users to be sensible, but mistakes happen, and I\

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 07:01

    You could create a temporary table to circumvent side effects of the query:

    CREATE TEMPORARY TABLE users SELECT * FROM users;
    INSERT INTO users(name) VALUES('UniqueName');
    DROP TABLE users;
    SELECT * FROM users WHERE name='UniqueName'; -- Should return 0 results
    

提交回复
热议问题