For me: I created an user with no privileges
GRANT USAGE ON *.* TO `command_user`@`localhost
And I execute mysql command on this user.
And use the try-catch block -> if syntax error => false, else => true
try-catch
false
true