connect to mysql

Ask about the individual Gambas components here.
Post Reply
tailkinker
Newbie
Posts: 40
Joined: Tue Sep 17, 2024 11:06 am

connect to mysql

Post 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()
User avatar
thatbruce
Regular
Posts: 312
Joined: Sat Sep 04, 2021 11:29 pm
Location: Sitting at my desk in South Australia

Re: connect to mysql

Post 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.)
tailkinker
Newbie
Posts: 40
Joined: Tue Sep 17, 2024 11:06 am

Re: connect to mysql

Post 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.
User avatar
sholzy
Site Director
Posts: 228
Joined: Sat Nov 26, 2016 2:52 am
Location: Florida

Re: connect to mysql

Post 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.
sholzy
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
tailkinker
Newbie
Posts: 40
Joined: Tue Sep 17, 2024 11:06 am

Re: connect to mysql

Post 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!
User avatar
gbWilly
Site Admin
Posts: 368
Joined: Fri Sep 23, 2016 11:41 am
Location: Netherlands
Contact:

Re: connect to mysql

Post 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.
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- Gambas3 Debian/Ubuntu repositories

- GambOS

... there is always a Catch if things go wrong!
tailkinker
Newbie
Posts: 40
Joined: Tue Sep 17, 2024 11:06 am

Re: connect to mysql

Post 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.
User avatar
BruceSteers
Legend
Posts: 2186
Joined: Thu Jul 23, 2020 5:20 pm
Location: Isle of Wight

Re: connect to mysql

Post 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.
tailkinker
Newbie
Posts: 40
Joined: Tue Sep 17, 2024 11:06 am

Re: connect to mysql

Post 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.
Post Reply