Recent

Author Topic: check if mysql/mariadb database exists  (Read 2210 times)

bdexterholland

  • Jr. Member
  • **
  • Posts: 62
  • uh?
check if mysql/mariadb database exists
« on: January 08, 2022, 01:30:31 am »
hi guys!

well, i`m planning to make a wizard to my system. If database doesn`t exist then run script to create a startup database.

wonderful, miracle, champagne for all

but:
* if database doesn`t exist MySQL57Conn raises ESQLDatabase Error;
* if database exists but login is wrong MySQL57Conn raises ESQLDatabase Error;
* if database exist, login is right but password is wrong MySQL57Conn raises ESQLDatabase Error;

How can I check if database doesn`t exist?
[sleep .....]

BSaidus

  • Sr. Member
  • ****
  • Posts: 411
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: check if mysql/mariadb database exists
« Reply #1 on: January 08, 2022, 01:45:37 am »
Do execute SQL query
Code: SQL  [Select][+][-]
  1. SHOW DATABASES
in a query and see in result if your database exists.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

PierceNg

  • Full Member
  • ***
  • Posts: 192
Re: check if mysql/mariadb database exists
« Reply #2 on: January 08, 2022, 02:45:35 am »
Even if database exists it may be some other database that happens to have the same name. So next thing to do is to verify the schema. Which your application will have to do eventually for its database due to evolving schema.




bdexterholland

  • Jr. Member
  • **
  • Posts: 62
  • uh?
Re: check if mysql/mariadb database exists
« Reply #3 on: January 08, 2022, 02:31:28 pm »
Do execute SQL query
Code: SQL  [Select][+][-]
  1. SHOW DATABASES
in a query and see in result if your database exists.

OK, but you use a TSQLQuery and connect to mysql schema before run this command?

TMySQL<xx>Connection needs to specify a database before connect
« Last Edit: January 08, 2022, 04:30:17 pm by bdexterholland »
[sleep .....]

bdexterholland

  • Jr. Member
  • **
  • Posts: 62
  • uh?
Re: check if mysql/mariadb database exists
« Reply #4 on: January 08, 2022, 02:35:47 pm »
Even if database exists it may be some other database that happens to have the same name. So next thing to do is to verify the schema. Which your application will have to do eventually for its database due to evolving schema.
That`s a good point but for now i`m not worrying about it. Maybe a second step. For now, who should use my software probably don`t have a mysql installed for another systems. This is for a first run or a recovery...
« Last Edit: January 08, 2022, 03:49:17 pm by bdexterholland »
[sleep .....]

 

TinyPortal © 2005-2018