netbeans建项目和mysql连接,无法在NetBeans IDE中建立与MySQL的连接

When I create a new web project with Hibernate, I open New Connection Wizard, choose MySQL (Connector/J driver) option (connector jar appears in the Driver Files list), I press the Next button, set Host: 127.0.0.1, Port: 3306, databasename, User Name: root, blank password field. Then I get 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))

Here is the code from the config.inc.php file:

/* 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;

There is a couple of other config.inc.php files in XAMPP's folder (in Ubuntu), but those don't seem to contain username and password settings. There are following lines in the /etc/mysql/my.cnf file:

user = mysql

socket = /var/run/mysqld/mysqld.sock

port = 3306

basedir = /usr

datadir = /var/lib/mysql

tmpdir = /tmp

So, I probably set the right port. What does this user = mysql mean? Why may this "cannot establish a connection" error appear with these settings? Thanks in advance.

解决方案

user = mysql is the OS user under which the MySQL daemon runs. From the error message, it appears that the MySQL user root has a non-blank password. You should determine what that password is and put it in the authentication config.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值