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.