java.sql.SQLSyntaxErrorException: Access denied for user 'SIT'@'%' to database 'SIT'
means the MySQL user SIT does not have sufficient privileges on the database SIT.
Here’s how you can fix it in MySQL 8.4:
Step 1: Log in as a privileged user
Connect with root or another admin account:
root > mysql -u root -p
Step 2: Check if the user SIT exists
mysql> SELECT user, host FROM mysql.user WHERE user='SIT';
If no row is returned, create the user:
CREATE USER 'SIT'@'%' IDENTIFIED BY 'your_password';
Step 3: Grant privileges on the database
Give the user access to the SIT database:
mysql> GRANT ALL PRIVILEGES ON SIT.* TO 'SIT'@'%';
Or if you want only read/write:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON SIT.* TO 'SIT'@'%';
Step 4: Apply changes
mysql> FLUSH PRIVILEGES;
Step 5: Test the connection
From your Java app or CLI:
# mysql -u SIT -p -h <your_host> SIT
No comments:
Post a Comment