com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:拒绝用户"@'localhost"访问数据库
问题描述:
我想连接到数据库并使用Java创建表. Butm它引发以下异常:
I want to connect to my database and create the tables using Java. Butm It throws below exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:访问 拒绝用户"@'localhost"进入数据库
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database
答
检查是否允许用户进行远程连接,在数据库上的sql query下面运行以允许您的用户从任何地方进行连接.
Check if user is allowed for remote connection, run below sql query on your database to allow your user to connect from everywhere.
允许用户从任何地方连接
`GRANT ALL ON *.* to <user-name>@'<ip>' IDENTIFIED BY '<password>'`
root
用户的示例:-
GRANT ALL ON *.* to root@'%' IDENTIFIED BY 'root';
// grant root user to connect from everywhere(%) , which has root password.