I am trying to write a script which allows a user to select the what manipulation he needs to do on a table. I want to check if the table exists or not. If it exists I will continue the other things or else I exit saying table doesn't exist. How might I achieve this.
| |||||
feedback
|
|
If you want a method that doesn't involve running a mysql client and logging in to the mysql server, you can do this:
You will have to replace the path to your data directory, your database name and your table name in the first line. Caveats:
It's not as reliable as the other methods presented already because of the reasons above but it avoids the mysql client so it may still be worthwhile. Note that all methods presented here rely on your getting your own permissions (filesystem or MySQL) correct. If you get them wrong you will most likely get a false negative. | |||
|
feedback
|
|
For this problem I call the following method as root:
Note that this is for postgresql for mysql you should change the psql -l to mysql's list table command (ie. the line in Glen's answer). | ||||
|
feedback
|
|
In MySQL you can use -e from the shell
| ||||
|
feedback
|