access denied when trying to connect to mysql using tomcat datasource - mysql

I'm trying to connect locally to mysql 5 server in jsp page using tomcat 6 and datasource.
I've configured everything as in the tomcat manual (web.xml, context.xml, etc.), but I get this exception:
java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)
I checked the mysql and there is no problem with the connection itself, in fact I even succeeded connecting using direct JDBC connection (i.e. without using datasource).
Do I need to set anything in the tomcat policy file? other ideas?
Thanks

I found a workaround, though I don't like it because I don't understand why it isn't mentioned anywhere, and why the permissions for the connector is not enough?
Can anyone explain me?
The workaround - add these lines to your tomcat policy file:
grant {
permission java.net.SocketPermission "localhost:3306", "connect, resolve";
};

Related

Netbeans won't connect to MySQL server

I installed Netbeans IDE 8.2 on Windows 10 and disconnected MySQL 8.0 because I planned to use JDBC, without realizing that the inherent connection was already using it. I now want to reconnect, but after entering all the information into the connect pane it gives me the error "Cannot establish a connection to jdbc:mysql://localhost:3306/mysql using com.mysql.jdbc.Driver (Unable to load authentication plugin 'caching_sha2_password'.)"
Screenshot of error.
Has anyone else had this issue and has someone figured out how to fix it?
The problem does not seem to be with a password as I entered it correctly. Netbeans is "Unable to load authentication plugin 'caching_sha2_password'."
Create a new user with standard security login.
You can use standard Type, SHA256 Password or caching_sha_password.
Also, grant permissions to database that you want to access.

Amazon EC2 Tomcat7 instance unable to access MySQL db on same system

I think I've seen a variety of similar posts on this topic, but am still unable to resolve my issue, so I figured I'd post with my specifics.
I have an Amazon AWS Linux EC2 instance running Tomcat7 web server. On the same machine I am also running a MySQL5 server, but I am unable to get the Tomcat app to talk to the MySQL database.
My Java app on tomcat tries to connect to MySQL by reading from a properties file:
jdbc.mysql.host.path=jdbc:mysql://localhost/
jdbc.mysql.schema=prod
jdbc.mysql.username=root
jdbc.mysql.password=<password>
I am accessing the app from another system via web browser, but when the app tries to connect to the database I get the following error in catalina.out:
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
I'm pretty sure the issue has to do with permissions and communication between Tomcat and MySQL, because I've written a simple java program utilizing the same code to read the same properties file, and the connection is made successfully.
Here are some things I have attempted to remedy the issue:
change the owner of the properties file (currently owned by 'Tomcat')
ensured that user 'root' has been granted all privileges in MySQL
ensured that port 3306 (MySQL default port) is accessible by my test server
updated iptables made various modifications to /etc/my.cnf file
(tried to bind ip, but that didn't work)
I have a hunch that the issue may be related to the fact that I am trying to access the MySQL database using user 'root'. Even though I'm accessing it via localhost, the system may not support this because MySQL treats this as access from a separate host and (maybe?) root access from other hosts isn't allowed?
Any suggestions on things to try would be greatly appreciated...
I believe the issue was a combination of things.
Here are some items to consider that ultimately fixed it for me:
- making sure you were accessing the correct app via browser (I was using ROOT app, but trying to connect to another one)
- making sure a user exists in MySQL using 'Create User ....'
- making sure all privileges are granted on the database in question, for some reason granting all privileges on . wasn't working for me

Tomcat7 MySQL Connection Error

I'm facing a perplexing problem. I've completed a jsf web app that utlizes hibernate and infinispan with Tomcat7 and tomcat-jdbc-pool as the connection pool provider.
It is being deployed to a Linode cluster w/ 2 nodes -- one database server and one production server.
I can run the app on my local environment using the exact same copy of Tomcat7 (I literally tarred the tomcat directory and promoted it to the server to debug this error) -- even when connected to the live database instance. Everything runs fine.
When I attempt to run the application from the production server I get a MySQLIO error:
Caused by: java.net.ConnectException:
Connection refused
Looking further up in the logs i see:
The last packet sent successfully to
the server was 1 milliseconds ago. The
driver has not received any packets
from the server.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure
I can connect from the command line on the prodapp server just fine -- even using tcp:
mysql -h db01 -u user -p --protocol=tcp
But it just won't work running inside the Tomcat container. I've tried all kinds of things but I'm really stumped. It just seems strange that I can connect to the database server using the same copy of Tomcat7 locally but when deployed to production the same copy of tomcat7 can't connect -- even though I can connect from the command line on that production server ... I'm stumped.
Any help is greatly appreciated.
EDIT: Solved my problem after wasting too much good life on it. The answer was I'm stupid. Thanks to everyone who tried to help. I have the app moded w/ a dev and live mode and the connection pool was reading the dev mode this whole time. What really made it confusing is that the sessionfactory was moded to live so it would actually reach the live database and initialize a connection when it started up so i could see it connecting (and running meta data queries in the mysql log), but when it actually went to grab a connection from infinispan it blew up. Oh well -- at least it's working now. Thanks again.
If you're connecting to your MySQL database server from a different box, then you need to explicitly grant permission for that user account to connect from that IP.
You can do this whilst in the command line:
GRANT ALL PRIVILEGES ON *.* TO 'username'#'ip_address'
EDIT: Granting all permissions on all tables generally isn't required, be specific about what permissions you want to grant (http://dev.mysql.com/doc/refman/5.1/en/grant.html)
To see what permissions you currently have:
USE mysql;
SELECT * FROM users;
My apologies if I'm patronising you, just that this is the most common problem that I come across.

Connecting Funambol to MySQL on remote host

I am setting up Funambol 8.7 on a Linux host (using Amazon AWS). I need to connect to a MySQL datbase that is hosted on a different server.
Per the administration guide I went ahead and downloaded the mysql connector and placed the jar in /opt/Funambol/tools/jre-1.6.0/lib/ext. I changed the install.properties file as follows:
dbms=mysql
jdbc.classpath=/opt/Funambol/tools/jre-1.6.0/jre/lib/ext/mysql-connector-java-5.1.14-bin.jar
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://myserver.net/rugcutte_funambol?characterEncoding=UTF-8
jdbc.user=rugcutte_funambo
jdbc.password=funambol
THen I try to run the install, but get the following error:
/opt/Funambol/ds-server/install/install.xml:452: java.sql.SQLException: Access denied for user 'rugcutte_funambo'#'ec2-50-16-233-200.compute-1.amazonaws.com' (using password: YES)
It appears my AWS instance can connect successfully to my MySQL database however it is trying to login with a fully qualified user name that is incorrect: rugcutte_funambo'#'ec2-50-16-233-200.compute-1.amazonaws.com
I tried also to change the line to : jdbc.user=rugcutte_funambo#myserver.net . But I got a similar error with that as well.
I am relatively inexperienced to JDBC. What is the proper way to set up this section of the install.properties file?
Did you enable access to that database with that user from that server?
What happens if you try and just make the same mysql connection from the command line from your Funambol server?
Thanks Adam.
You led me to the correct answer. The remote host has an area in cPanel to configure Remote Database Access Hosts. So I did, need to add my source host that is running Funambol, to my list of access hosts.
After this I ran the install and it did, appear to create the tables properly in the database running on my remote host.

Connecting Coldfusion 9 with MySql 5 on Ubuntu 9.10

I've recently set up a Ubuntu 9.10 server with a LAMP configuration and then installed Coldfusion 9 Development version as well.
I've got phpMyAdmin working, so MySql and PHP are fine, and I can serve coldfusion pages, but if I cannot verify my Coldfusion datasource. I get the following error:
Could not create connection to
database server. Attempted reconnect 3
times. Giving up.
With the top of the stack trace showing
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Could not create connection to
database server. Attempted reconnect 3
times. Giving up.
These are my settings for the datasource in the Coldfusion administrator
JDBC URL jdbc:mysql://192.168.1.19:3306/dbname
Drive class com.mysql.jdbc.Driver
Driver name ConnectorJ 5.1.7
And I know the username and password are correct as they're the same ones I use for phpMyAdmin. Does anyone have any ideas why it's not working?
I'm using almost the same configuration on few boxes and have no such problems, so it looks like you are misconfiguring the datasource.
Are you trying to create the dsn with "MySQL (4/5)" driver? I'm not sure how to read your settings string properly. Is that IP is your localhost? If yes, why not try to use the localhost for server name.
It's a permissions problem. The IP needed to be 192.168.1.19 in the DSN setup in the administrator, but that didn't fix it alone.
I also created a 'temp' MySQL user based on a post found here: http://www.linuxquestions.org/questions/showthread.php?p=4039359#post4039359
And used that instead, it worked.
Try using 127.0.0.1 as the MySQL server address in your DSN configuration