java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

This can help you:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '%password%' WITH GRANT OPTION;

Execute it with command line or some GUI tool.

Don't forget to replace %password% with real password.


As you are creating a database from scratch, you could use:

Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/?user=root&password=rootpassword"); 
PreparedStatement ps = connection.prepareStatement("CREATE DATABASE databasename");
int result = ps.executeUpdate();

Here is an identical scenario.


This is specific to Ubuntu 18.04 LTS and MySQL 5.x Followed this link Follow everything from here onwards:

sudo mysql_secure_installation

sudo mysql

Once logged into MySQL then from the MySQL prompt execute these commands:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;

Now verify that the table has the password for the root

SELECT user,authentication_string,plugin,host FROM mysql.user;

This solved my issue and now i am able to login.