Cannot establish a connection to MySQL in NetBeans IDE

流过昼夜 提交于 2019-12-31 03:53:06

问题


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.


回答1:


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.




回答2:


When I added a downloaded connector jar to the Driver Files list it worked. Somehow /home/myname/Downloads/mysql-connector-java-5.1.18/mysql-connector-java-5.1.18-bin.jar in this list works, but the native IDE's /home/myname/netbeans-7.0.1/ide/modules/ext/mysql-connector-java-5.1.13-bin.jar doesn't.



来源:https://stackoverflow.com/questions/9594494/cannot-establish-a-connection-to-mysql-in-netbeans-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!