List:MySQL and Java« Previous MessageNext Message »
From:Martin Hollyer Date:June 1 1999 4:40am
Subject:What are Unix Sockets and What Port does the database use?
View as plain text  
What are Unix Sockets and What Port does the database use?
=========================================================
 
Martin Hollyer, MySQL newbie here.  I have done a number of
servlet JDBC applications with JDBC and Access.
 
Recently, I installed MySQL on my local Window NT computer
and have had no difficulty connecting to MySQL on my local machine.

In order to create Java Database applications, I have to know the
port number my database uses.  With MySQL on my Local WinNT
machine, I type the status command:

    status
 
    mysql  Ver 9.13 Distrib 3.21.13a-gamma, for Win/95 i586
 
    Connection id:          7
    Current database:       hollyer
    Current user:           tr003073@localhost
    Server version          3.21.29a-gamma-debug
    Protocol version        10
    Connection              Localhost via TCP/ip
    TCP Port                3306
    Uptime:                 2 hours 1 minute 1 second
 
    Threads: 3  Questions: 673 Slow queries: 0  Opens: 76 Flush tables: 1  Open
    tables: 7
    --------------                                 
 
This gives me the port number (3306) from a TCP/IP connection.  
 
However, on my Internet Provider's Solaris computer, the UNIX Sockets
are given instead (/tmp/mysql.sock) with no ports specified.


    mysql  Ver 9.27 Distrib 3.22.13-beta, for sun-solaris2.6 (sparc)
 
    Connection id:          289
    Current database:       hollyer
    Current user:           tr003073@localhost
    Server version          3.22.13-beta
    Protocol version        10
    Connection              Localhost via UNIX socket
    UNIX socket             /tmp/mysql.sock
    Uptime:                 9 days 6 hours 57 min 8 sec
 
    Threads: 3  Questions: 2949  Slow queries: 0  Opens: 265  Flush tables: 1  Open
    tables: 62
    --------------                                 
 
How do I find out to which port number I need to connect?
 
Do I have to use UNIX Sockets in my application code?  I have
tried using /tmp/mysql.socket in my ViewDB.java application as 
part of the JDBC connection but received the following error.

                // force loading of the jdbc.odbc Driver
                Class.forName("org.gjt.mm.mysql.Driver");


                // connect to the database
                mmCon = DriverManager.getConnection(
                "jdbc:mysql://localhost:/tmp/mysql.sock/databaseName",
                "user","pass");  // ** note /tmp/mysql/sock for Port Number
                                       // ** obviously will give a
                                       // ** NumberFormatException because the code
                                       // ** is expecting a Port number instead of
                                       // ** /tmp/mysql.sock

                // create Statements
                myStmt = mmCon.createStatement();
 
Indeed a NumberFormatException is given:

java.lang.NumberFormatException: /
        at java.lang.Throwable.<init>(Compiled Code)
        at java.lang.Exception.<init>(Compiled Code)
        at java.lang.RuntimeException.<init>(Compiled Code)
        at java.lang.IllegalArgumentException.<init>(Compiled Code)
        at java.lang.NumberFormatException.<init>(Compiled Code)
        at java.lang.Integer.parseInt(Compiled Code)
        at java.lang.Integer.parseInt(Compiled Code)
        at org.gjt.mm.mysql.Driver.port(Compiled Code)
        at org.gjt.mm.mysql.Driver.connect(Compiled Code)
        at java.sql.DriverManager.getConnection(Compiled Code)
        at java.sql.DriverManager.getConnection(Compiled Code)
        at ViewDB.<init>(Compiled Code)
        at ViewDB.main(Compiled Code)  

Conversely, when I substitute the default port on my Windows NT machine when trying
to get a Connection, a NullPointerException is given.  Most likely because I have not
connected to the right Port.

So do I connect to the server using code like the following to establish a
port?

Socket s = new Socket("localhost/tmp/mysql.sock", 3306); //????????


Any help with the above would be greatly appreciated.


Martin Hollyer

Thread
What are Unix Sockets and What Port does the database use?Martin Hollyer1 Jun
  • Re: What are Unix Sockets and What Port does the database use?David Wall1 Jun
  • Re: What are Unix Sockets and What Port does the database use?Paul DuBois1 Jun
  • Re: What are Unix Sockets and What Port does the database use?Martin Hollyer2 Jun