[Qt-interest] retreive list of databases from MySQL database

Andre Somers andre at familiesomers.nl
Tue Mar 9 13:44:46 CET 2010


Robert Hairgrove wrote:
> Andre Somers wrote:
>   
>> Hi,
>>
>> I am trying to show the user of my application a list of available 
>> databases to connect to on my SQL database. MySQL features the SHOW 
>> DATABASES command. Is there some way to issue this command using 
>> QSqlQuery before actually connecting to a known database on the server?
>>
>> André
>>     
>
>  From the MySQL docs (look at chapter 19.1):
>
> " The following statements are equivalent:
>
> SELECT SCHEMA_NAME AS `Database`
>    FROM INFORMATION_SCHEMA.SCHEMATA
>    [WHERE SCHEMA_NAME LIKE 'wild']
>
> SHOW DATABASES
>    [LIKE 'wild']"
>
> If the user which has logged into the MySQL server has SELECT privileges 
> on the INFORMATION_SCHEMA database, you can use that SELECT statement to 
> do what you want. If not, it won't work (you also cannot use SHOW 
> DATABASES with that user account).
>   
Thanks. That is helpful. I will try to log into the INFORMATION_SCHEMA 
database with the known user credentials, and retreive the databases if 
the connection succeeded. That should work then I guess.

André





More information about the Qt-interest-old mailing list