Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Why Close A DB Connection?


Why should I close a DB connection?

I have asked this question somewhat before, but never received a solid answer, like "it's good practice", but why?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
When To Close Sql Connection
I made a website in php that is with sql. I have include files for my header, leftcol, rightcol, main, and footer. I have sql queries inside each include file. My question is when do i need to close the connection to sql and where does the closing operation need to be. Or do i just leave the connection open?

Client Ignores Close Of Connection?
we're seeing strange behaviour of mysql connections over network here
lately. Server and client are on different machines. Server (corpdb) is
Mysql 3.23.52 on FreeBSD 4.6.2-RELEASE, client is php application
(portal), Mysql-client 3.23.55, PHP 4.2.3, Apache 1.3.27 on FreeBSD
4.8-RELEASE. The boxes are connected over Cisco Catalyst switch in the
same LAN. There is ipf firewall running on portal, no firewall running
on corpdb.

The problem we're seeing is manifesting as failure to connect to mysql
server from the php application (pconnect function). I did tcpdump
traces on both machines, and my theory what's happening follows:

Imagine long time open and idle connection. Mysql server decides to
close this connection (13:55:06), it sends FIN to client. Client ACKs
the FIN, but not send his FIN as in ordinary TCP connection close.
Server closes the connection on his end, but client is keeping
connection opened on his end. After half hour (14:28:25) client want to
talk to the server and sends packet (P) to server. Server no longer have
opened connection on that port, responds with RST. Client replies with
FIN and returns connection error to PHP.

My question here is: where could be bug? I suspect mysql client....

Open And Close Time 2000 Kills The Connection
I am moving some data from a text file into mysql and my code in c# using ODBC fails.

Actually I created a loop to test mysql and realized that mysql goes banans when

for(int i=0; i < 5000; i++) {
connection.Open();
connection.Close();
}

This code is for illustration purposes ONLY but it should work!? When I reache around 2000 the connection.Open() loses the connection to localhost and terminates the program! After a minute I can get access to mysql again? Inserting a delay of 100ms seems to keep things going.

Close A Database?
Ok, i know how to open and close a MySQL database with PHP.

But i'm really confuse when is the right time to close it after opening?
PLease if you have a bright answer and detailed and smart explaination for
this please don't hesitate to share it to me, because i want to know it.

Must One Close A MySQL Database?
I've got a little PHP/MySQL learning project where I'm simply storing links to sites, for display. One page shows the categories to choose from, and when the user makes a choice we jump to the next page which does a query on the category and displays all matching links.

People will be going back and forth between the two pages, which makes me want to open the database and table once and leave it open. The alternative is repeated opening/closing.. which must introduce quite a bit of overhead.

The problem is if the user simply leaves either page, which they presumably will at some point, the database will never be closed via an actual close statement.

What happens in a case like that? In my testing I can't find any downside to doing this, but I suspect there must be one

How Do I Close An Open Table?
After I finish the SELECT function, I want to close the table I opened just before. Which command can I use to do so?

How Do I Close An Open Table?
After I finish the SELECT function, I want to close the table I opened just before. Which command can I use to do so?

Auto Close Forum Posts
Need help writing a query that checks the date a particular forum post was posted, compares it with the current date. If there is a difference of 30 days, the forum post should be closed.

The database table is called "Discussions"
The "DateCreated" Field of a particular post is Datetime type in the form 2007-04-12 09:21:46

Compare this date of every post with current date, if more than 30 days have passed, then add a 1 to the "Closed" field.

Ibdata1 Is Close To Disk Size
I am running MySQL 4.0.13 with my-medium.cnf (attached) on a Solaris 8, 4x450
Mhz, 4gb RAM. All my tables are InnoDB. Currently my ibdata1 is 1.8 gb. I have
about 1 gig space left on the same partition. Also it is excruciatingly slow
now. How do prevent the ibdata1 from filling up the disk partition ? How do I
increase the speed on my MySQL? Code:

Ibdata1 Is Close To Disk Size
I am running MySQL 4.0.13 with my-medium.cnf (attached) on a Solaris 8, 4x450 Mhz, 4gb RAM. All my tables are InnoDB. Currently my ibdata1 is 1.8 gb. I have about 1 gig space left on the same partition. Also it is excruciatingly slow now. How do prevent the ibdata1 from filling up the disk partition ? How do I increase the speed on my MySQL?

[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
myisam_sort_buffer_size = 8M
query_cache_size = 16M
query_cache_limit = 8M

log-bin
server-id = 1

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/var/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/var/
#innodb_log_arch_dir = /usr/local/mysql/var/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

( I had to comment the innodb to stop crashing )

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

Close Mysql Port Or Bind It To Only Localhost Or ...
I only use mysql locally. I want to

- close port 3306 if possible (like starting Oracle database without
starting listener),
- or bind it to localhost only (like what sendmail does),
- or next best thing

for security.

I am on redhat 9, and use mysql 3.23.55. I can upgrade if newer
version provide the functionality.

Changes Made In One Connection Does Not Reveal In Another Connection At Once.
I use many connection and the same as many threads in my server app to gain performance on a multicpu machine.

Firstlly i call "set autocommit=0" and wrap every statements with "start transaction " and "commit". i use mysql_stmt_execute for every statement rather than mysql_real_execute except those that can't be prepared. The version of mysql is 4.1.11 under Debian linux.

In one connection of one THREAD i insert a row into a table. After i got the sucess code and the last insert id, i then do a "select" from another connection in another THREAD with the "last insert id" return by the previous insert . I expect the select can fetch the row that i have just insert , but some time it does and some time it doesn't.

is there any funtion like "mysql_....flush...cache.." to make the changes from one connection to be reveal to the global at once?

Searching For Numbers - &quot;close To&quot; Or &quot;approximate&quot;
I would like to know how to search a table for records where a particular field is "close to" a particular number.

For instance, let's say I have a table containing students and their most recent test scores. I'd like to see students who scored 7/10. That's easy enough (select * from table where score = 7). I'd also like to run another query to identify other students whose scores are not 7 but "close to" 7. Ie students who scored 6 or 8.

As an added bonus, I'd like to be able to do a related search that shows students who scored 7, then shows the other students ordered by how "close" they are to 7. Ie students who scored 6 or 8 are "closest" matches, and students who scored 1 are "furthest". I hope this makes sense!

Is there any pre-existing MySQL command that will do this? Or will I have to run separate queries for each value?

Connection
I installed MySQL 5.0 in my machine. I'm using a software (EMS SQL Manager) and i try to create a new database. I need to make a connection with MySQL server but the following error its occurs: Access denied for user root@localhost (using password NO).

Connection
when connecting to mysql i get an error message as
"Access denied for user: 'abc@abc.com' (Using password: YES)" .

Connection
I just installed mysql 4.0 .There were many problems
with upgrading from 3.23 to 4.0 so I deleted 3.23 and
made a fresh start with 4.0. Everything works fine now
but the only problem to connect to the server is via
the /usr/local/mysql/bin directory. Is there a way to
connect if I am root.

Connection
I have installed mysql by yum (on fedora core 3): yum install mysql
And I want connected me, I have the following message:

ERROR 2002: Can't connect to local Mysql server through socket '/var/lib/mysql/mysql.sock' (2)

Connection
I have a mysql database running on my server and i want to let someone else connect to it.

Using cPanel and WHM on a Linux box.

This is the error we are getting on the other site:

Unable to connect to database server!
Host 'server14.******.com' is not allowed to connect to this MySQL server

How can i allow there server to connect?

Php Connection
I have installed mysql 4.1 and things are working. I select the program from the start menu and it takes me straight to the command prompt where I type in the password I set upon installation. When connecting to mysql server using php you have to specify:
$host = "";
$user = "";
$pass = "";
$connect = mysql_connect($host, $user, $pass);

The problem is that I don't know what's my user? or my host for that matter. I assume since its installed locally the $host would be 'localhost' but how do I find out my $user? Or can I just simply type in a $host and $pass alone? and leave out the $user? While I am here, can someone point me to some really good mysql tutorials. Not the ones mixed with php, just plain mysql.

Connection
The database has already been made and is installed in http://TL28serv and has a dsn of "warehouse".

It says to connect to the database you need to use the following connection string:

myconn.open"warehouse","IWSDstudent","assign2"
(this is assuming that the connection object you create is called myconn).

Does any one know how to create this connection object? and how to use the connection string?

Connection
Yesterday I was able to connect and work with the database.

Today, I cannot connect. I do not remember changing anything.

I repaired Apache2. Do no know if it needed a repair.

Reinstalled mysql. Seemed to be my problem.

When trying to open mysql@localhost, I receive an error Access denied for
the user name@localhost Using password

I reentered the password.

Still no success.

What am I missing??

The icon for Apache is green.

The Icon for mysql admin is green.

Connection
I've downloaded mysql and php to my computer. I am also running the latest version of apache. But im really confused how to get mysql to work with my domain. When i use the php script to connect to mysql using localhost as the "hostname" everthing works fine, but thats just looking at it on my local computer. How do I do it for my site that is actually on the web.

Can I still use localhost as the host name or do I have to get another one somehow? If so how do I set it up?

Connection
I keep getting connection lost errors from a DOS windows mysql client
on Windows 2000 from which I access a MySQL server (3.23.58) on RH9
(located on a dedicated server outside the country).

ERROR 2006: MySQL server has gone away
No connection. Trying to reconnect...

SQL statements are okay, tables are okay but whenever I stay idle for
a few seconds, I get an error. If I retry, I get a reconnect and
everything goes well... Then the same thing happens again. I have
set all timeout parameters to a few hours and it doesn't help? What
could cause that, any idea?

Connection
Code:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:Documents and Settingsdy>cd C:mysqlin
C:mysqlin>mysqladmin -u root password abc
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to MySQL server on 'localhost' (10061)'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'
when i want to set my root password, thw following error message shows.
how can i connect to my SQL server? i am running it for learning purpose.what should i do to fix this problem?
is it installing Apache would be ok for that ?

Connection
I am using C to access and query MYSQL DB(on HP UX 11i). Evrything works fine for 1 query to mysql Db. Problem starts when i try to give more than 5 requests to the same DB. I am using PERL to give many request to my program, which inturns give request to the MYSQL.

NOTE: Many THREADS are using the MYSQL DB at a time.

The errors i get are :
2003 2004 2006 (all realted to lost connection from the mysql server)

and Segemntation fault error.

I have tried increasing the server parameters like "max_connections" "heap size" and various other parameters.

Connection Do Database Using Psp
I use a hosting company for my websites. I have created a mysql dabase using my hosting company's control panel. Now, I am trying to figure how I connect to it to enter data.

MYsql Connection/PHP
I am getting the following message, when I installed mysql client version 5.1.11. I get this message when I tried to connect through PHP. I am using, windows XP professional.

"Client does not support authentication protocol requested by server; consider upgrading MySQL client"

MyODCB 3.51 And DSN-Less Connection
I am using Micorosoft Access 2000 as a fornt end and MySQL as a back end.

I hope someone may be help me to clarify the following:

Q.1. Where do I specify cursor location to be adUseClient

Q.2. Where do I specify cursor type to be adOpenStatic

Q.3. Where do I specify lock types to be adLockOptimistic

Connection Lost
I have an unusual problem with the error "Lost connection to MySQL sever
during query". I receive this message only when querying one table in a
database. All other tables and queries work fine.

5.0.1 Connection Problems
I have installed 5.0.1 on RH Enterprise V.3 Everything is fine locally. When I try to connect with ODBC from a remote PC via excel, navicat, MysqlAdmin,Control Center, Toad, etc., etc. The connection takes at least 10 seconds and navigating the tables and admin is very slow. I only have this issue with 5.0.1. Does anyone have a clue as to why this is happening? I am stumped...older versions are almost instant. This has become a major roadblock for me as the lag is unacceptable for what we need. If anyone has experienced this let me know or if you have solved this please share.

Asp Connection Strings
I am a novice at using database websites.  I need to connect to a MySQL database on a remote server using ASP......

I have been given the following by tech support at my ISP (Fasthosts).....

"DRIVER={MySQL ODBC 3.51 Driver};SERVER=data.domain.com;PORT=3306;DATABASE=myDatabase; USER=myUsername;PASSWORD=myPassword;OPTION=3;"

My questions are

Is "DRIVER" a Memory Variable, and if so,

Does "DRIVER" gain a value (True or False) if the connection is successful or not (respectively)?

Can anybody let me have a more complete ASP script which will let me know if the connection has been sucessful or not.

Connection To Database
is the syntax the same as connecting to mssql using asp?? this is how i connect to mssql using asp:

Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = SErver.CreateObject("ADODB.Recordset")
strConn = "DSN=FYP_Actual;Driver={SQL SERVER}; UID=sa;pwd=;"
Conn.Open strConn

is this the same way i connect to mySQL too?

Connection To MySQL Using .net
I am trying to connect to a MySQL database, using the .Net framework.

I installed the newest MyODCB (3.51) and the .Net ODBC drivers from
Microsoft.

I made a System DSN using the driver, and i get it to connect - so far
so good.

But if i try making a new connection i my code using the sample
connectionstring from MySQL, i get an Exception :(

"An OLE DB Provider was not specified in the ConnectionString. An
example would be, 'Provider=SQLOLEDB;'."

What i try is:

Return New OleDb.OleDbCommand("DRIVER={MySQL ODBC 3.51
Driver};SERVER=localhost;DATABASE=bigshop;UID=root ;PASSWORD=;OPTION=3;")

Remote Connection
How do i connect to a remote (webserver) Mysql from the windows command line?

PHP Connection To MySQL
I'm working on a simple script to create two tables within a database, and I'm sure its just some stupid error I'm making, but I cannot seem to get it to work! Here's my function: Code:

Connection Problem
I have a computer i am slowing building into a web server. I have Apache 2.0, PHP4.2.3 (i think, PHP4 anyways), and MYSQL 4.1 running on windows 2000.

I wanted to run PHPNuke on it right now, but i am having problems connecting to my MYSQL. I can't seem to get the login information on my PHPNuke config file right, and I have no idea where to get it. I try localhost, root, my pw, and the table name, but no dice. Tried many different things.

Is there somewhere in mysql, mysql admin, or the Control center that tells you the correct information? I am rather new to this, can you even connect a php program to MYSQL if they are on the same computer?

MySQL-PHP Connection
the problem i'm facing is of mySQL-PHP connection. i'm trying ...

<?
$link = mysql_connect("localhost",'root','nawal')or die("Connect Error: ".mysql_error());
print "Successfully connected.
";
mysql_close($link);
?>

and getting this message...

Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:Program FilesApache GroupApache2htdocs estindex.php on line 5

Connect Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client.

Too Many Connection Problem
There are only 5 users surfing my website, and I suffer from too many connection problem. I use freebsd and mysql-server-4.0.24 with vBulletin.

Here is my my.cnf file:
[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
socket=/tmp/mysql.sock

[mysql]
no-auto-rehash
set-variable = connect_timeout=12
set-variable = max_connections=1000
#mysql.allow_persistent=Off

Is there anything wrong with my configuration?

Lost Connection
I am getting this error "ERROR 2013: Lost connection to MySQL server
during query" when i try to connect from one client, on all other
clients i don't have any problems connecting to specific server.
Also from this client i can connect to the other servers without any
problem.

Connection Problems
When I try to connect to the MySQL server I get this message:

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61)

I used the mysql_connect("localhost", "username", "pass") function. I don't know what this problem precisely means or solve it.

Connection Count
I've got a problem getting the count of the users that are connected to a mysql-db in combination with a terminal server (win2k3)

I can get the processlist from mysql, but all the hostname's in that list are the terminal server itself, and not the users connected through the terminal server.
(http://dev.mysql.com/doc/refman/5.1/en/show-processlist.html)

How can I get these adresses ?

MySQL Connection Over LAN.
I have installed mySQL server on a computer (ServerName: AHMED, ip:192.162.0.1) and teh server listens at port:3306.

I type "mysql -u root -p" on command line to connect to the server on local host.

Now I want to connect to the same server over the network from a computer (ComputerName: FARAZ, ip: 192.168.0.2). I Copied mysql.exe to the client PC (FARAZ) and I typed the line "mysql AHMED -u root -p" on FARAZ (Client PC) but It says that it fails to find any mySQL sever on AHMED.

1] If I only have to copy mysql.exe on the client to access mySQL server over a network.
2] Am I right to type "mysql AHMED -u root -p" on the client to connect to the mySQL server?

HTTP Connection
Can anyone give me some brief description on how to establish HTTP connection from MySQL as we use UTL_TCP.CONNECTION in Oracle.

Connection Needs Too Long
I have a MySQL Server 5.0.21 with a Windows NT 5.0 System and try to connect with en Delphi application through ZEOS-Components over local network.

My Problem is that the connect to the WinNT server needs nearly 20 seconds, where a connection to an Windows 2000 system just needs 1 second.

Are there any problems that i should know?

Lost Connection
I send a big INSERT request to the mysql server and I very often get a 'Lost connection to MySQL server during query' error. Though the client and the server are on the same machine.... Is there any way to avoid this problem ?

MySQL Connection
I just install PHP5 and MySQL5. They all work but I can't connect to MySQL via php connection (mysql_connect). Could you tell me what is the matter?

Slow Connection
I build an application and installed it on many machines. In every machine except two, the program works without problems. On this two, the connection with database is too slow.

I saw the opened doors with 'netstat' and the computer opens about 5 or 6 ports (to the port 3306 of the mysql server) before sucessfuly connect with MySql Database and execute the sql. I don't know what could be happening. I realy need to fix this because the progrm is too slow with this error. Could anyone know what could be happening??

Closing Connection
Like in many database MSDE, SQLSERVER etc, once you are done with database you close the connection

Conn.close
Set Conn = Nothing

Do we do any such thing in MYSQL?

Closing The Connection
When i am closing the browser window all the active open connections to the db must be closed. Is it possible to do this, how?? I am using Java Servlets and Mysql.


Copyright © 2005-08 www.BigResource.com, All rights reserved