【问题标题】:Cannot establish a connection to MySQL in NetBeans IDE无法在 NetBeans IDE 中建立与 MySQL 的连接
【发布时间】:2012-03-24 13:38:47
【问题描述】:

当我用 Hibernate 创建一个新的 web 项目时,我打开 New Connection Wizard,选择 MySQL (Connector/J driver) 选项(连接器 jar 出现在 Driver Files 列表中),我按下 Next 按钮,设置 Host: 127.0. 0.1,端口:3306,数据库名,用户名:root,空白密码字段。然后我得到cannot establish a connection to jdbc:mysql://127.0.0.1:3306/databasename using com.mysql.jdbc.Driver (Access denied for user 'root'@'localhost' (using password: YES))

这是来自 config.inc.php 文件的代码:

/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = true;

XAMPP 的文件夹中(在 Ubuntu 中)还有几个其他的 config.inc.php 文件,但这些文件似乎不包含用户名和密码设置。 /etc/mysql/my.cnf 文件中有以下几行:

user        = mysql
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp

所以,我可能设置了正确的端口。 user = mysql 是什么意思?为什么这些设置会出现“无法建立连接”错误?提前致谢。

【问题讨论】:

    标签: mysql netbeans jdbc xampp


    【解决方案1】:

    user = mysql 是运行 MySQL 守护程序的操作系统用户。从错误消息看来,MySQL 用户 root 的密码不是空的。您应该确定该密码是什么并将其放入身份验证配置中。

    【讨论】:

    • 谢谢。我刚刚找到答案,将在一分钟内写出来。密码实际上是空白的。
    【解决方案2】:

    当我将下载的连接器 jar 添加到驱动程序文件列表时,它起作用了。不知何故,此列表中的 /home/myname/Downloads/mysql-connector-java-5.1.18/mysql-connector-java-5.1.18-bin.jar 有效,但本机 IDE 的 /home/myname/netbeans-7.0.1/ide/modules/ext/mysql-connector-java-5.1.13-bin.jar 无效。

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 2014-12-25
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      • 2015-05-31
      • 2014-10-17
      • 2020-05-05
      • 2019-05-11
      相关资源
      最近更新 更多