gpt4 book ai didi

mysql - 无法使用 SQuirreL 连接到 MySQL 数据库

转载 作者:可可西里 更新时间:2023-11-01 07:39:50 25 4
gpt4 key购买 nike

我在使用客户端 Squirrel SQL 连接到 MySQL 时遇到问题。我以前设法连接到 Oracle 和 Derby,但是这次,我不知道我做错了什么。

我已经按照以下步骤在我的 Mac 上安装了 MySQL:

  1. 安装 MySQL:

    ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
    brew install git
    brew update
    brew install mysql
  2. 要确保安装安全:

    mysql.server start
    mysql_secure_installation
    mysql.server stop
  3. 创建新数据库:

    mysql.server start
    mysql -uroot -pmypassord
    create database mydb;
    show databases;
  4. 了解数据库的存储位置:

    mysql.server start
    mysql -uroot -pmypassword
    SELECT @@datadir, @@innodb_data_home_dir
  5. 创建表

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

在我执行了这些步骤之后:

  • MySQL安装在/usr/local/Cellar/mysql/5.6.17下
  • 数据库存放在/usr/local/var/mysql/mydb下
  • 表 tblemployee 已成功创建。

然后在 SQuirreL 中,我继续安装 MySQL 的驱动程序 (mysql-connector-java-5.1.30-bin) 并创建一个别名,URL 为“jdbc:mysql:/usr/local/var/mysql/mydb” ,用户名为“root”,密码为“mypassword”。

但是当我尝试连接时,我收到以下错误消息:

Unexpected Error occurred attempting to open an SQL connection.

当我点击 Stack Trace 时,这就是我得到的:

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

我做错了什么?

最佳答案

检查你的 jdbc 连接 URL,它似乎是无效的: 'jdbc:mysql:/usr/local/var/mysql/mydb'

Jdbc url 类似于“jdbc:mysql:/database”,因此应该类似于: 'jdbc:mysql:localhost/mydb'

关于mysql - 无法使用 SQuirreL 连接到 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22888240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com