Yesterday, Ron Cripe emailed me asking if I knew of any simple examples of how to use Tcl/Tk with MySQL. I knew about mysqltcl and pointed him in that direction, but he said he needed an actual example on how to use it.
I’ve done a lot of Tcl programming but have mostly avoided doing GUI’s with Tk, so I figured this might be a good opportunity to do some learning, myself. I quickly wrote a simple application that connects to a MySQL database, then lets you execute queries against it and displays the results. You can download it here:
- mysqltcl-client.tcl.txt (5KB)
It’s named .txt to make it easier to download–just rename it to only .tcl (removing the .txt) once you’ve saved it.
When you start the app, it presents you with a simple login dialog:
Enter your username and password, change the host, port and database values if necessary, and press Enter or click the Connect button. If all goes well, the login dialog will go away and the query window will appear:
This is an example of what the query dialog looks like after executing a SHOW TABLES query. Very simple, not terribly exciting, but what do you want for a 5KB, 181-line Tcl script?
If you have Tcl, Tk and mysqltcl installed, go ahead and grab a copy of this script and check it out. If you have questions about the code, just ask: I’ll try my best to answer them.
Tags: Tcl, Tk, MySQL, programming, open source
Hi Dossy,
I feel so lucky to found this website..It sound interesting to me since I am also work on tcl and mysql (mysqtcl) and looking for this quite very long time. I have some problem with mysqltcl that I hope you can answer.
OK..let me explain, I want to access the mysql database from tcl code, so I have installed mysql5.0.4 and mysqltcl3.0.2 and I already have tcl8.3.2 installed with the linux package (i am using debian). My mysql and tcl is working fine. The problem now is I can’t connect both of them using mysqltcl..I am using command “mysql::connect” but it returned “bash:command not found”..the installation was succesfull, but I dont have any idea why this happened. Actually I am totally new in mysqltcl, I just follow the command from the manual. So I want to ask you if u have any idea on how to connect them using mysqltcl..
Thanks in advance for you time and help!!
newbie36: Are you executing your Tcl script correctly? If you’re getting a “bash: command not found” error, it doesn’t sound like it. It sounds like you’re trying to execute Tcl code from your shell prompt, not as a Tcl script.
I’ll need more specific details (i.e., see exactly what you’re doing) to really give you any help with this.
Hi Dossy,
Really appreciate your quick response!..
Let me make you more clear. I need to store and retrieve some data into mysql database using tcl script, so I installed mysqltcl in order fo me to get access directly into the database from the tcl right?
Ok, actually, after installing mysqltcl, am I suppose to connect both of them via the mysqltcl shell prompt like I said in the previous post (::mysql::connect), or use the command in tcl scripts? I have tried to google on how to connect them both, but very much little info I get..when I type #mysqld_safe -u root mysql, it returned : ” Cant connect to localhost through var/lib/mysqld/mysqld.sock” (and this file actually is not exist) even though I didn’t installed it here.
And if I type #mysqld_safe, It will returned
“Starting mysqld daemon using var/lib/mysql, STARTED”,
but then just a few second, it will stopped by displaying
“STOPPING the server using var/lib/mysql/ns2-box.pid” .
I tried to point to the correct library path by using –with-mysql-var=/path/to/mysql/data during configure, but I dont know why this error still came out (even I have changed the path).
Maybe this is not the correct way of connecting them (that’s why I got those errors). Do i need to perform this command at mysqltcl shell prompt? or it should be applied in the tcl script itself? I really need to clarify this out since I have been stucked with this about a week!..I really hope you can help me in this and I really appreciate it!..
Sorry for my bad English, I hope you can understand.
Hi,
execute “package require mysqltcl” to check if installed. if installed it should give out the mysqltcl version like 3.03. If the command gives a error put ur mysqltcl package in tcl/lib and then try!!!!!!!!!!
hello readers and author…i having some kind of difficulty..hoping that you can help me..can anyone tell me how to install mysqltcl on windows vista or point to me any resources that useful to me..i kinda stuck with this problem now in my project..tq
i have try according what godfather says..still got the same error..please someone help me..
How did you install Tcl? Are you using ActiveState’s ActiveTcl distribution? How did you install mysqltcl? Did you download precompiled binaries?
please help me..
i install my Tcl using the Activestate ActiveTcl 8.5.7..im using MySQL server 5.1…and i download the Windows Binary Version of mysqltcl with zip packed mysqltcl Release 3.05..after that i extracted the package into Tcl\lib as instructed…and i dont know what to do after that…how to compile this thing? i am really clueless right now…
If you are using the binary version, you don’t compile anything. At this point, you should be able to start a Tcl shell and type “package require mysqltcl” in it.
If this is proving to be too difficult, you may want to stop trying to do this with Tcl.
im wondering..if i dont put the Tcl directory to the path in my system environment variable..can this cause the error? anyway..tq for you help..but since i develop my application using Tcl/Tk..its kind of hard to use another language to interface with the database..
When you attempt to “package require mysqltcl” do you get a Tcl error?
yes..cant find package mysqltcl…what do you suggest man?
Do you have libmysql.dll from the MySQL installation? Put a copy of that in your Tcl/lib directory, too.
still error man..what about the load command? i try type “load mysqltcl”..it give error “couldn’t load library “mysqltcl”: this library or a dependent library could not
be found in library path”…what do u think man?
You have to specify the full name. Assuming you installed ActiveTcl in C:/Tcl —
load C:/Tcl/lib/mysqltcl.dll
i just spot this..there are no mysqltcl.dll in tcl\lib and also in mysqltcl package..is this file suppose to be in mysqltcl package or do i need download it separately?
Actually, it’s libmysqltcl.dll and libmySQL.dll – do you have both of those in Tcl/lib dir?
hi..
I’ve been trying to install tclmysql on solaris 10. can you give me any tutorial about it. actually, i’m going to make login interface that connected to mysql. any help would be appreciated.. thanks
Hi, Andre – sorry, I really can’t help you with installing it on Solaris 10. Have you tried contacting Artur Trzewik, the current maintainer of mysqltcl?
I would appreciate it if you could tell me if this scrip that I have written (slightly modifies your connect function) is the right way. SA_telnet_puts is just a print command on the application that uses this script.
Looks fine to me. Are you getting an error?
Yeah. Thanks for the quick reply. Not an error it’s just not connecting. It’s printing Can’t connect!. Any suggestions
You may want to include
$err
in the “can’t connect” side of theif
clause, so you can see the reason for the error.Thanks. This helps a lot in the debugging I can get the error. Apparently there is some problem in my arguments. I’ll look into it. Thanks for the help