Page 1 of 1
connect to mysql
Posted: Fri May 30, 2025 10:28 am
by tailkinker
For my recipe program there are 3 different functions and several different formats for the output. Ex. If I am developing a recipe, sometimes I need to dig deep into the nutrient comparisons between nutrient types get the same mouth feel as I would in a higher saturated fat recipe - classic case being ice cream. Other times I might be looking a digestibility factors and neutralizing anti-nutrients. Finally, there is the shorter form for my cookbooks.
In Visual Basic, I store my formatting cues for tables in a database so I can open different child forms with different formats.
I created a database using mysql workbench, but am getting an error unknown database. I have already verified mysql server is running, and credentials are correct.
I also tried exchanging gb.db2 and gb.db2.mysql for the deprecated gb.db, but there was no change in the error. Also the database name is showing up on the left hand side along with my .csv files.
Here is my code:
in gambas class
public getdb as new connection
public procedure fordbopen()
getdb.close
getdb.type = "mysql"
getdb.host = "localhost"
getdb.login = "myusername"
getdb.port = "3306"
getdb.name = "displaydb"
getdb.password = "mypasswordfordb"
getdb.open()
Re: connect to mysql
Posted: Fri May 30, 2025 12:27 pm
by thatbruce
Exactly where does the error occur?
My first guess is on the
getdb.close
line. If so, it's because you are trying to close a Connection that hasn't even been set up yet.
(Standard response: Dont use mysql, its a dog. Use MariaDB instead.)
Re: connect to mysql
Posted: Fri May 30, 2025 12:42 pm
by tailkinker
Bruce,
Thankyou for the tip on MariaDB, I will check that out.
I tried taking out the close connection, but still got the same error. It is stopping on the last line - getdb.open()
Also I noticed the following in the console:
mysql_opt_reconnect is deprecated and will be removed in a future version.
Re: connect to mysql
Posted: Fri May 30, 2025 1:21 pm
by sholzy
The only difference I can see between your's and mine, is you use "localhost" and I use "127.0.0.1".
Try adding "db.Debug = True" as the first line in your fordbopen().
You should get something like
Code: Select all
2025-05-30 08:59:29.431 gb.db.mysql: 0x55b544cfc330: select left(version(),6)
2025-05-30 08:59:29.431 gb.db.mysql: 0x55b544cfc330: set names 'utf8'
2025-05-30 08:59:29.432 gb.db.mysql: 0x55b544cfc330: show variables like 'character_set_client'
if your connection is actually opening.
Re: connect to mysql
Posted: Fri May 30, 2025 4:29 pm
by tailkinker
I tried adding the db.debug line, and didn't get any output from it.
Also tried changing localhost to numerical address. That also didn't work.
Database opens fine in mysql workbench.
Update - apparently I am trying to use the mysql workbench file, not the actual database. Now I have to figure out how to create the database.
Also found dbeaver, so maybe I will try mariadb through that if I can't turn the script generated by workbench into a database.
Definitely got spoiled with Visual Basic on this one!
Re: connect to mysql
Posted: Fri May 30, 2025 6:38 pm
by gbWilly
Very easy and user friendly manner of managing mysql/mariadb databases is using phpmyadmin.
You run in in your browser and can create databases, tables and such, manage users.
The other method is using cli to do above. Less user friendly, more direct and without an API.
Re: connect to mysql
Posted: Fri May 30, 2025 8:20 pm
by tailkinker
Ahhhh... I forgot about phpmyadmin, although I noodled around in it a few years ago for a website I was building. Will check that out. thanks.
Re: connect to mysql
Posted: Fri May 30, 2025 8:46 pm
by BruceSteers
google AI wrote:
To export a MySQL database in MySQL Workbench, navigate to Server > Data Export. Choose the database you want to export, select whether to dump structure and data, and choose a local destination file. Then, start the export.
Here's a more detailed breakdown:
1. Open MySQL Workbench and connect to your server:
Establish a connection to the MySQL server containing the database you want to export.
2. Access Data Export:
Go to the Server menu and select Data Export.
3. Select Database and Objects:
In the Data Export pane, choose the database you want to export and specify whether to export the structure (table definitions) and data (table content).
4. Choose Export Options:
You can choose to export to a single SQL file, a project folder, or multiple files (one per table).
5. Configure Advanced Options:
If needed, refine the export operation by adding table locks, using REPLACE statements instead of INSERT, or quoting identifiers.
6. Start the Export:
Click Start Export to initiate the export process. The progress will be displayed.
7. Locate the Exported File:
The exported SQL file will be saved to the location you specified during the export process.
Then i think you would use the Connection.URL property for the exported file.
Re: connect to mysql
Posted: Sat May 31, 2025 10:33 pm
by tailkinker
Ok, finally there is some joy. I wound up using phpmyadmin to create the mysql database (I will delve into mariadb later on and also conquer mysql workbench.)
Database opens fine now.