开发者

Get list of MySQL databases, and server version?

开发者 https://www.devze.com 2023-01-11 16:45 出处:网络
My connection string for MySQL is: \"Server=localhost;User ID=root;Password=123;pooling=yes;charset=utf8;DataBase=.;\"

My connection string for MySQL is:

"Server=localhost;User ID=root;Password=123;pooling=yes;charset=utf8;DataBase=.;"

My questions are :

  1. What query should I write to get database names that exist?
  2. What query should I write to get server version?
  3. I have error because of my connection string ends w开发者_如何学Cith DataBase=. What should I write instead of the dot?


  1. SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
  2. SELECT VARIABLE_NAME, VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'VERSION'
  3. Use INFORMATION_SCHEMA as the database.


To get the list of databases, you can use SHOW DATABASES:

SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.01 sec)

To get the version number of your MySQL Server, you can use SELECT VERSION():

SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.1.45    |
+-----------+
1 row in set (0.01 sec)

As for the question about the connection string, you'd want to put a database name instead of the dot, such as Database=test.


show Databases; 

Will return you all the registered databases.

And

show variables;

will return a bunch of name value pairs, one of which is the version number.

0

精彩评论

暂无评论...
验证码 换一张
取 消