[Solved] MySQL server connection and database selection with SQLdb lazarus / 16-Databases ---------------------------------------------------------------------- jcmontherock · 2023-12-31 14:42 Could we split the connection to the server and the database selection ? I want the user can choose the database. For that I should connect to the server and give the db list in a comboBox. I could connect with a dummy database (mysql for ex) and after the user choice, close the connection and reconnect with the real database. This second connection to the server is useless and take ressources. Is a way to connect to server and then change the selected database without a second connection ? ---------------------------------------------------------------------- BSaidus · 2023-12-31 16:20 Yes, When you connect to MySQL/MariaDB, the authentification is usally used to mysql database. After connecting, you execute Code: SQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SHOW DATABASES  in query and display all databases in the system (say in combobox). Then give the user a choice. Be sure that the user/password for the user have a restricted privileges. PS: which component you use to ? SQLDB or Zeos ? ---------------------------------------------------------------------- jcmontherock · 2023-12-31 16:33 see the title of my topic... ---------------------------------------------------------------------- BSaidus · 2023-12-31 16:55 Ok, Do Mysql connection to mysql database with user/password credential. After db connect, use TSQLQuery to retrieve list of databases in the server. Give user to choose any db he want and Disconnect/reconnect to the chosen database. ---------------------------------------------------------------------- Zvoni · 2024-01-02 07:55 Huh? Why not just fire off a "USE ByUserSelectedDatabase" SQL-Command? Untested Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //Connect to "mysql" with User/PW etc.//Let User choose a DatabaseMyStillOpenConnection.ExecuteDirect('USE '+ChosenDatabaseName+';');  //Or ExecSQL. Don't remember anymore//Check if correct DB was selectedMyQuery.SQL.Text:='SELECT DATABASE();';MyQuery.Open;//Writeln(MyQuery.Fields[0].ToString); Of course, logged in User must have Access-Rights to that "new" Database ---------------------------------------------------------------------- jcmontherock · 2024-01-02 15:44 Thanks a lot. I forgot this sql statement...