Can't connect to MySQL from webapp in Ubuntu - mysql

I have a MySQL database I'm able to connect via the command prompt and the MySQL administration tool but using the same credentials in a Web application in a Tomcat server on the same server gives me this error:
javax.servlet.ServletException: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
Which I recognize as an incorrect credentials issue. I checked that the MySQL server is listening on port 3306 using netstat. I don't have the mysql root credentials but I created a new account and granted all priviledges to it and are the ones used to connect both using the command prompt and the MySQL admin tool.

Turned out to be a caching issue. Disabled the context caching in the web application in order to "see" the changes. Windows doesn't show this behavior/issue.

Related

Mysql not accepting connections from some sources

I have a MySQL server (v8.0) running on windows server 2016. I also have IIS running and PHPMyAdmin installed. In addition to this, I have a PHP web application which runs on the same server (under IIS) which accesses the MySQL database. Finally, I have several Python scripts which access the MySQL database.
Somehow, I have lost the ability to access the database from the Python scripts, but the web application still works and PHPMyAdmin can see and modify the database.
Even more strangely, I can no longer user MySQL Workbench to access the server from a PC on the local network, and PHPMyAdmin cannot access the users table of the mysql database. I can't change user details at all through PHPMyAdmin, I get the error:
Error in processing request
Error code: 500
Error text: Internal Server Error (rejected)
It seems that the connection to server has been lost.
MySQL Workbench gives me this error:
Your connection attempt failed for user 'user' to the MySQL server at SERVERADDRESS:PORT:
Access denied for user 'user'#'SERVERADDRESS' (using password: YES)
I have checked that the server can accept connections from remote computers by adding bind-address=0.0.0.0 to the my.ini file. I have also checked to ensure that 3306 is allowed through the firewall.
Any ideas on what could be causing this issue?
ADyson and MrApnea pointed me in the right direction.
The problem was caused by my main database user having the host reset from % to localhost, I'm not sure how this happened or when. As the app was running locally, this was not affected, but all other access was denied (including MySQL workbench). My root user is set to local only for security.
To fix this, I connected to the server via RDP and logged in to the console as the root user. I then ran these commands to see the error:
use mysql;
select host, user from user;
This showed me that the main user account had "localhost" in the host. I ran this command to update this user:
update user set host='%' where user='username' and host='localhost'; flush privileges;

Remote MySql Database CPanel

I want to connect a remote MySql database from MySql workbench but I got an error:
"IO Error: [Errno None] Unable to connect to port 22 on or
xx.xx.xx.xx"
What should I do?
I already add my IP to remote host
when I delete IP that makes the error, then I'm trying to connect, that IP showed up again in my remote host
So how can I connect to my database from MySQLWorkbench?
How to Connect to a Database with MySQL Workbench
One tool you can use to connect to remotely connect to databases on your shared, VPS, or Dedicated hosting account is MySQL Workbench. MySQL Workbench is a free tool you can use to connect to your server databases from your personal computer. MySQL Workbench can be Downloaded for free at the following link:
http://dev.mysql.com/downloads/workbench/
You will want to use the Windows (x86, 32-bit), MSI Installer if you are on Windows. The file we are installing in this tutorial is the mysql-workbench-gpl-5.2.47-win32.msi file.
Once you have downloaded MySQL Workbench, you can install it onto your computer. After you have the program installed, follow the steps below to set up a remote connection.
Add IP to your Remote MySQL
In order for you to be able to connect to your databases remotely you will need to add your local computer IP address to the Remote MySQL in cPanel.
Steps to connect to your database remotely
Open MySQL Workbench.
Click New Connection towards the bottom left of MySQL Workbench.
In the "Set up a New Connection Dialogue" box, Type your Database
connection credentials.
The credentials will be like the following:
Connection Name: You can name this whatever you like.
Connection Method: Standard (TCP/IP).
Hostname: You can use your domain our your cPanel IP address.
Port: 3306
Username: Your cPanel username or the user you created for the
database.
Password: cPanel password or the password for the database user that
was created.
Default Schema: This can be left blank.
Click Test Connection.
Type your password and click the "Save Password in Vault" check box.
Click Ok.
MySQL Workbench should say "Connection parameters are correct". Click Ok.
Click Ok again to accept the connection settings.
Now under the SQL Development section you will see your connection listed in the Open Connection to Start Querying box. Click your newly created account.
Now you will see the databases list in the area on the left.

Remotely connect to an aws-windows instance based MySQL Database

I have launched an AWS EC2 Windows_Server-2016 instance.
Since this server is windows based,I can successfully connect to
it using remote desktop connection by entering the username,
password and a .ppk file.
I have installed MySQL server on the instance and created a user
that is allowed to login with any ip i.e by providing the '%' sign.
Here's what my AWS instance security group looks like :
I have tried connecting to the MySQL server using SQLYOG using 2
different scenarios :
Tried connecting by using the aws public ipv4 address as a host field and
using mysql username & password
Tried connecting by creating an SSH connection i.e providing server
username/password and .ppk file in SSH connection panel & then
providing mysql host/username and localhost in mysql connection
panel
None of the methods used allows me to connect.I try same procedure with a linux based server and can connect successfully. Please let me know where am I going wrong while using a windows based MySQL hosting.
MySQL has an extra level of IP protection for remote clients. You have to GRANT access to the remote ip(your house of office) to be able to connect. As root, you have to do :
GRANT ALL ON <db>.* TO '<username>'#'<remote ip>' IDENTIFIED BY '<remote_password>';
Where is the DB you are trying to connect to etc.

cannot connect remotely with online database on localhost phpmyadmin

i have configured the phpmyadmin's config.inc.php file and a drop down menu has appeared accordingly in localhost/phpmyadmin to select the server. But when i try to connect to the server it says:
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.
i have added my ip address to the online host server in the cpanel and have access to the remote sql connection.
please help.
Most hosts block incoming connections to the MySQL server as a security measure. You'll have to ask your host about unblocking port 3306 and how to access your MySQL directly -- or run an API on your web host, which would have access to the MySQL server due to being on the same network, and access the database through that. For phpMyAdmin specifically, just install it on your web host instead of your local machine, then access it through the internet rather than localhost.

How to connect to otrs MySQL database using mysqlworkbench

We have a Linux Vm which is running our OTRS. I have found the kernel file which has the database configuration details. In there the host name is listed as local host.
I tried using the server IP address along with the database username that is there; however I cannot seem to connect.
I also cannot find the port that is utilized. How do I connect to the database on mysqlworkbench,
Maybe server doesn't allow remote connections to the DB or user used by OTRS is only a local user?
If this is true you've got two options:
Create user that is allowed to login remotelyCreate user that is allowed to login remotely
Create user that is allowed to login remotely
Use Standart (TCP/IP) over SSH as connection method in MySQL workbench. This option allows to first connect over SSH to the server and than connect to the DB as local user