简体   繁体   中英

MYSQL Connection: Access Denied

These are my codes for the database connection:

Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection("jdbc:mysql://10.44.222.111/try?" 
+ "user=jenny&password=perez");

After running the program, it display this error :

com.mysql.jdbc.exception.jdbc4.MySQLSyntaxErrorException:
Access denied for user 'jenny' @ '%' to database 'try'

I am using MySQL Workbench.

Go to MySQL Workbench, then User Privileges, click your username, then check all Administrative Roles then click apply. This will allow connection for user 'jenny'.

As the error says, user 'jenny' does not have access to connect to database from any host(%). On mysql prompt, run the following command to provide privileges to user 'jenny' to connect from any host.

GRANT ALL PRIVILEGES ON try.* TO 'jenny'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

You may use specific PRIVILEGES instead of ALL as per your requirement.

This would indicate that your user does not have permission to access that database from any client host ('%').

MySQL uses a four part mechanism for allowing access:

  • username
  • password
  • database
  • client host

You need to make sure that the user is authorised in MySql to access the 'try' database and is allowed to connect from any client host ('%') and has the correct username and password.

Also, you should ensure you are connecting to port 3306 (unless MySQL is running on a non-standard port).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM