问题
I need to be sure the database I'm connecting to is MySQL and not PostgreSQL or Microsoft SQL Server.How can I find out which type of database is being used .
回答1:
The first hint might be the "connection error" you're likely to get if you try to connect to a PostgreSQL database with a mySQL database driver :)
Basically, you need to:
1) Code your application in a portable manner (don't use MSSQL extensions in a query that might be run on mySql, for example)
2) Choose a portable driver API (like JDBC, ODBC, ADO.Net, etc)
3) Provide some mechanism for your application to query the actual database type at runtime (for example, an .config properties file)
4) Test your completed application against each of the supported database types.
'Hope that helps .. PSM
回答2:
You can check for the running database process on the host your trying to connect.
Example: ps -ef | grep mysql
回答3:
Judging from your comments, you have an SQL CLI-like interface or you can only execute SQL queries and you want to know if it's a mysql server answering your queries.
You could use
SELECT @@version_comment
which will return something like MySQL Community Server
if it's a MySQL server
来源:https://stackoverflow.com/questions/9917037/how-to-detect-database-type