[英]JDBC Access denied error
I am trying to deploy my application to another server, and while the JDBC connection worked in my machine, I couldn't get it to work with this mysql server. 我试图将我的应用程序部署到另一台服务器上,尽管JDBC连接在我的机器上正常工作,但无法使其与该mysql服务器一起使用。
Some information about the mysql server: 有关mysql服务器的一些信息:
select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
mysql> show variables where Variable_name="port";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
There is no password to login into the mysql with user localhost ( mysql -u root will be enough to login) 没有密码可以使用localhost用户登录mysql( mysql -u root足以登录)
I used the following statement to connect to the database 我使用以下语句连接到数据库
DriverManager.getConnection(
"jdbc:mysql://localhost:3306/database_name", "root", ""));
But, It throws the following error 但是,它引发以下错误
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
Any suggestions? 有什么建议么? Thanks.
谢谢。
you need to in %MYSQL_INSTALL_PATH%/bin folder,using cmd and run: 您需要使用cmd在%MYSQL_INSTALL_PATH%/ bin文件夹中并运行:
mysqld -nt --skip-grant-tables
mysqladmin -u root flush-privileges password "NEW_PASSWORD"
and restart mysql service. 然后重启 mysql服务。
Have you tried mysql -u root -p
, with the password field not provided? 您是否尝试过
mysql -u root -p
,但未提供密码字段? I guess here's the problem "jdbc:mysql://localhost:3306/database_name", "root", ""));
我猜这是问题
"jdbc:mysql://localhost:3306/database_name", "root", ""));
you used a ""
as your password so I think you need to do this mysql -u root -p
您使用
""
作为密码,所以我认为您需要执行此操作mysql -u root -p
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.