List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:June 14 1999 3:37pm
Subject:Re: socket problem with DBI connection
View as plain text  
>> Hello !
>>
>> Thanks for response but I think I don't really understand how mysql uses
>> sockets.
>> I didn't change the 3306 port (i'm sure because my win ODBC is configured
>to
>> use it and it works)
>> But I know that safe_mysqld script starts mysqld with param
>>
>> --socket=/tmp/.my.socket
>>
>> (this cannot be changed with my permissions)
>> when I want to use mysql shell I must start it like this:
>>
>> mysql --socket=/tmp/.my.socket
>>
>> (without --socket i get "Can't connect to local MySQL server")
>>
>> So, how can I do it in DBI ??
>>
>> I'll be very thankful for response because it's a serious problem to me.
>> Chris.
>Hi
>Same as previous response :). In you pler script you should have as follow
>
>use DBI;
>$dbh=DBI->connect( "DBI:mysql:dbname=dbname:port", "dbusername",
>"dbpassword");
>
>This will return the DB handle in $dbh. You will then use this handle to
>perform whatever query u want to this particular DB.
>Replace port with the port number. To find yout which port MySQL is running
>at you could do
>
>mysqladmin -u yourusername -p variables
>
>You will then be prompted  by the password challange. If you have access
>then you will see the list of  MySQL vairables.
>The variable you are looking for is
>port
>Put the value u found here in
>DBI->connect("DBI:mysql:dbname=dbname:port_number_you_found_here",
>"dbusername", "dbpassword");
>
>If you do not understand DBI then goto this URL:
>http://www.symbolstone.org/technology/perl/DBI/index.html it contains doc on
>DBI.

I didn't ask the original question, but I don't think I understand this
answer.  "port" is a TCP/IP port number.  The socket for a MySQL connection
is a UNIX domain socket name (a pathname).

perldoc DBD::mysql says this:

     mysql_socket
                 As of MySQL 3.21.15, it is possible to choose
                 the Unix socket that is used for connecting to
                 the server. This is done, for example, with

                     mysql_socket=/dev/mysql

                 Usually there's no need for this option, unless
                 you are using another location for the socket
                 than that built into the client.

So, to specify the socket name, do something like this:

$db_name = "test";
$db_host = "localhost";
$dbh = DBI->connect (
        "DBI:mysql:$db_name:$db_host;mysql_socket=/tmp/mysql.sock",
        "user_name",
        "your_password",
        {PrintError => 0}
);

Replace /tmp/mysql.sock with the socket pathname that you want to use.
(/tmp/.my.socket, I guess)

--
Paul DuBois, paul@stripped
Northern League Chronicles: http://www.snake.net/nl/
Thread
socket problem with DBI connectionKrzysztof Wysocki14 Jun
  • Re: socket problem with DBI connectionOzemail)14 Jun
Re: socket problem with DBI connectionOzlinx)14 Jun
  • Re: socket problem with DBI connectionPaul DuBois14 Jun