5

I have trouble connecting to MySQL using the client Squirrel SQL. I managed to connect to Oracle and Derby previously, but this time, I do not know what I am doing wrong.

I have installed MySQL on my Mac, following these steps:

  1. To install MySQL:

    ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
    brew install git
    brew update
    brew install mysql
    
  2. To secure the installation:

    mysql.server start
    mysql_secure_installation
    mysql.server stop
    
  3. To create a new database:

    mysql.server start
    mysql -uroot -pmypassord
    create database mydb;
    show databases;
    
  4. To know where databases are stored:

    mysql.server start
    mysql -uroot -pmypassword
    SELECT @@datadir, @@innodb_data_home_dir
    
  5. To create a table

    use mydb;
    create table tblemployee (
        employeeID  int not null,
        firstname   varchar(50),
        lastname    varchar(50),
        titleID     int,
        salary      float,
        primary key (employeeID)
    );
    

After I followed these steps:

  • MySQL was installed under /usr/local/Cellar/mysql/5.6.17
  • The database is stored under /usr/local/var/mysql/mydb
  • The table tblemployee was created successfully.

In SQuirreL, I then proceeded to install MySQL's driver (mysql-connector-java-5.1.30-bin) and to create an alias with URL as "jdbc:mysql:/usr/local/var/mysql/mydb", User Name as "root" and Password as "mypassword".

But when I try to connect I get the following error message:

Unexpected Error occurred attempting to open an SQL connection.

When I click on Stack Trace, this is what I get:

java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.sql.SQLException: Unable to create connection. Check your URL.
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:202)
    at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.awaitConnection(Unknown Source)
    at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$100(Unknown Source)
    at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$2.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.RuntimeException: java.sql.SQLException: Unable to create connection. Check your URL.
    at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(Unknown Source)
    at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$000(Unknown Source)
    at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$1.run(Unknown Source)
    ... 5 more
Caused by: java.sql.SQLException: Unable to create connection. Check your URL.
    at net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager.getConnection(Unknown Source)
    ... 8 more

What am I doing wrong?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
lcazarre
  • 713
  • 3
  • 9
  • 15

2 Answers2

4

Check your jdbc connection URL, which seems to be invalid: 'jdbc:mysql:/usr/local/var/mysql/mydb'

Jdbc urls are something like 'jdbc:mysql:/database', so should be something like: 'jdbc:mysql:localhost/mydb'

ieee0
  • 41
  • 2
0

Once you have installed MySQL and created your database, you must go to SQL SQuirrel.

In SQuirrel, the first thing to do is install the appropriate drivers. In the case of MySQL:

  • Go to the "Drivers" (left side of the screen) tab.
  • Secondary click "MySQL Driver".
  • Click "Change".

It will open a dialog:

  • Name: The name you want to give the driver (leave it as is).
  • Example URL: jdbc: mysql://localhost/(database name)
  • Website: http://dev.mysql.com

Go to the "Extra Class Path" tab, and add the .jar MySQL connector. You'll find it in the folder where you installed MySQL. In my case it was "Program Files (x85) /MySQL/Connector.J 5.1 / mysql-connector-java-5.1.39-bin.jar" Give OK, and you will be ready the driver. Now, add a new Alias.

Go to this tab, and click the Add button (Blue Cross):

  • Name: The name you want to give the alias.
  • Driver: MySQL Driver
  • URL: By default, and have configured the driver installation.
  • User Name: root
  • Password: mypassword

And finally, you give the "OK" button and ready.

I hope you have been a clear enough explanation.

Greetings.

Javier Garcia
  • 61
  • 1
  • 5