Springboot successfully connects to mysql locally but can't connect after deploy - mysql

I'm using mysql 5.7 on my Mac to develop a springboot app with no problems.
Here are my properties:
logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
server.port=8091
spring.datasource.url=jdbc:mysql://localhost:3306/dbName
spring.datasource.username=useraa
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=false
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.format_sql = false
spring.jpa.properties.hibernate.default_schema=USERAA
After I deploy using mvn clean install and upload to my server on Digital Ocean, this error message shows when I run the .jar with command java -jar app.jar
java.sql.SQLException: Access denied for user 'useraa'#'localhost' (using password: YES)
with ERROR 28538 com.zaxxer.hikari.pool.HikariPool : testdb - Exception during pool initialization.
I checked my firewall settings already and I allow the port and I can connect to mysql using ssh/phpmyadmin with username 'useraa'.
I also tried a CRUD command in ssh.

You are connecting to MySQL but it is not authenticating you.
Check your username and password are correct
Check your username has access from local host
Check your username has privileges to the schema

Related

Access denied for user MySql

The problem is my localhost Laravel project just won't connect to MySQL, I get the following error:
Access denied for user 'root'#'localhost' (using password: YES)
OS: macos high sierra
Browser: Chrome;
MySql version: 8.0.12
Laravel version: 5.6
Homestead Version: 7.0
Things I have tried to fix it:
Checked that there is an instance of MySql running - It's running.
Check the credentials in the .env file and config/database.php - The credentials are correct (Mysql root user password has been change from the one generated on installation)
I checked if I could connect via terminal to double check that the credentials are correct - I can and they are correct
Tried creating a new MySql user with all root privileges. - same error.
I can run php artisan migrate in the terminal and the tables are created. which I thought was strange as the site is denied.
I completely removed MySql 3 times. (following this guide: https://gist.github.com/vitorbritto/0555879fe4414d18569d) - same error
So then I started from the beginning destroyed the vagrant box and Laravel project and started from the beginning - Same error.
Fought the urge to punch my computer.
.env (Updated)
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
yaml:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Sites
to: /home/vagrant/Sites
sites:
- map: site.test
to: /home/vagrant/Sites/sitetest/public
databases:
- homestead
/etc/hosts
##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 site.test
The default password for homestead is not something.
According to laravel docs it is secret.
A homestead database is configured for both MySQL and PostgreSQL out
of the box. For even more convenience, Laravel's .env file configures
the framework to use this database out of the box.
To connect to your MySQL or PostgreSQL database from your host
machine's database client, you should connect to 127.0.0.1 and port
33060 (MySQL) or 54320 (PostgreSQL). The username and password for
both databases is homestead / secret.
Docs at: https://laravel.com/docs/5.6/homestead
Update:
You can also grant your user the permissions to play with the database with:
GRANT ALL PRIVILEGES ON database_name.* TO 'username'#'localhost';
In the hosts file, when running Homestead, you'll have to change 127.0.0.1 site.test to 192.168.10.10 site.test
Of course that will only work after vagrant up
You can solve your problem by caching your config:
php artisan config:cache
Cd into your Homestead directory
run vagrant ssh
run php artisan migrate
try this
first inside in mysql run sudo mysql -u root -p
next execute this command :
use mysql;
update user set plugin='' where User="root";
flush priviliges;
exit

TALEND - Vagrant Mysql connexion issues

I'm pulling my hair over the following situation.
I'm unable to connect to my MySQL server in Vagrant (2.0.0 , OS: Ubuntu 16.04 ) with only specific applications (HeidiSQL and Talend 6.1).
This error happens with Talend MySQL components with the mysql-connector-java-5.1.30 jar and Java 1.8 JRE.
I receive the following error each time when connecting either directly (TCP/IP) or over SSH (TCP/IP over SSH) to the MySQL Server with the aforementionned applications:
Access denied for user 'user'#'IP' (using password: YES)
This however doesn't happens with MysqlWorkbench with both direct connection (TCP/IP) or over SSH with the same user credentials. Below are the settings of the MySQL server:
MySQL Server Network Info
Maria Db: 10.0.34
bind-address: 0.0.0.0
skip-name-resolve: true
The following have already been tried and tested:
Access credentials and privileges verification
DNS flush both on Guest and Host machines
Addition of MySQL server IP to host file
Verification of ports opening both on host and guest
The following solved the issue:
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'#'%' WITH **GRANT OPTION**;
The GRANT OPTION does the trick.
Alternatively this could be caused by wrong driver being used in your Talend workspace. To update the MySQL connector JAR follow the steps below:
Donwload the updated connector driver here
Replace the 'tMySQLOutput/tMySQLInput' component(s) with an equivalent tJDBC ones
Add the new connector JAR (No 2 on the image) and the class name com.mysql.jdbc.Driver (No 4 on the image) (ref https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-installing-classpath.html)

Linkedin WhereHows - Docker Backend not able to connect to MySQL

When I try to connect WhereHows backend to MySQL DB in Docker environment I am getting following error message (I checked IP, Username and Password and all 3 are good):
1) Error in custom provider, Configuration error: Configuration error[Cannot connect to database [wherehows]]
At the same time, WhereHows web is connecting without any problem.
Docker version is 17.12.0-ce and I am using following images:
wherehows/backend
wherehows/web
wherehows/mysql
This is my config file - /backend-service/conf/application.conf
# connection to wherehows mysql database
db.wherehows.driver = com.mysql.jdbc.Driver
db.wherehows.url="jdbc:mysql://localhost/wherehows?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false"
db.wherehows.username="wherehows"
db.wherehows.password="wherehows"

Connecting to remote DB from SpringBoot app located on server failed

I have deployed my app on RaspberryPi server which demands connection to remote MySql db. The properties looks like:
# LOCAL DATABASE
#spring.datasource.url = jdbc:mysql://localhost:3306/test3?autoReconnect=true&useSSL=false
#spring.datasource.username = root
#spring.datasource.password = admin
# REMOTE DATABASE
spring.datasource.url = jdbc:mysql://modraszka.sth.sth:8822/test3?autoReconnect=true&useSSL=false
spring.datasource.username = root
spring.datasource.password = password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
But while I try to run the app it throws that:
The remote DB is on the same server as app was deployed.
Seems your host mane is not valid one (modraszka.sth.sth).
Try to ping it.
If its working try to telnet using telnet modraszka.sth.sth 8822.
If telnet is not working try to telnet to telnet modraszka.sth.sth 22.
Then its not works for you we can assume you have to grant access to mysql port in the remote server.
Check if your remote database is open for the internet or as it's default, running only localy
grant remote access of MySQL database from any IP address

Server side forclose me to connect with remote database

I have created SpringBoot application which connectes to the remote database mysql. I test it with two remote db connection: one has a dynamic IP, the second one has a permanent IP - it's a hosting.
Running locally:
When I try to run application locally (connection to DB with permanent IP), straightforward from Intellij everything works properly - in my browser I can see the application.
When I try to run the application with dynamic IP - I need to provide the host name instead of IP, the application throws:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Caused by: java.sql.SQLException: null, message from server: "Host 'HomeGateway' is not allowed to connect to this MySQL server"
Running on server:
When I try to run it on server eventhough I provide the connection to the host with dynamic IP or with pernament IP it also throws:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Caused by: java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
The application.properties file looks like - the connection with database with dynamic IP:
# REMOTE DATABASE
spring.datasource.url = jdbc:mysql://modraszka.sth.sth:3336/test3?autoReconnect=true&useSSL=false
spring.datasource.username = root
spring.datasource.password = password
I must add that when the appication has been deployed at server, at the same server is located database - this one which has dynamic server - modraszka.sth.sth.
Summary:
Whenever I want to run the application from server which has connection to remote DB it always throws fails even when I want to connect to the DB which is located on the same server as my application. I also tried to run application with db properites connection as: localhost:3306/test3 -> but it also failed.