Remote MySQL Connection

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
bdgoecke
Posts: 36
Joined: Wed Oct 22, 2014 3:41 pm

Re: Remote MySQL Connection

Post by bdgoecke »

You need to use the "root" user.

(As from the example page, under Step 5, login as the root user)

Code: Select all

$ mysql -u root -p mysql
==>brian.
cchilderhose
Posts: 8
Joined: Fri Apr 26, 2013 9:08 am

Re: Remote MySQL Connection

Post by cchilderhose »

I tried to log in as Root to MySQL but get this -

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

So why is that and how do I get around it?
User avatar
lmiltchev
Former Nagios Staff
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Remote MySQL Connection

Post by lmiltchev »

If you are setting up mysql root password for the first time, you could run:

Code: Select all

mysqladmin -u root password NEWPASSWORD
If you want to change/update your password, you could run:

Code: Select all

mysqladmin -u root -p'oldpassword' password newpass
where you substitute "newpass" with your new password.

If you don't know the old mysql root password, you can reset it by following the steps, outlined here:

http://www.cyberciti.biz/tips/recover-m ... sword.html

Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
cchilderhose
Posts: 8
Joined: Fri Apr 26, 2013 9:08 am

Re: Remote MySQL Connection

Post by cchilderhose »

The reset article worked great and I got the root user password reset in MySQL.

Now I ran the commands for remote access in the original article and they were accepted. Now I still get the first message I posted about.

See attached.
NagiosConnectionError.png
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Remote MySQL Connection

Post by lmiltchev »

I would recommend reviewing the following document:

http://assets.nagios.com/downloads/nagi ... Server.pdf

It shows how to grant permissions to mysql user, how to allow a remote access to mysql, and how to test the connection. Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Remote MySQL Connection

Post by scottwilkerson »

You will also need to add permissions for your new user to connect from a remote IP like

Code: Select all

mysql -u USERNAME -p'PASSWORD' -h <YOUR_IP_ADDRES>
mysql -u USERNAME -p'PASSWORD' -h <YOUR_IP_ADDRESS>
And add a firewall rule

Code: Select all

/sbin/iptables -I INPUT -i eth0 -s <YOUR_IP_ADDRESS> -p tcp --destination-port 3306 -j ACCEPT
service iptables save
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
bdgoecke
Posts: 36
Joined: Wed Oct 22, 2014 3:41 pm

Re: Remote MySQL Connection

Post by bdgoecke »

The first set of instruction, were for a new database that would only be accessed from remote host.

Rather than update the user in the mysql.user table, you should be adding new access (rows in that table) for that remote access from an IP address.

You should change those entries in mysql.user back to 'localhost' (or your processes will be locked out when you PRIVILEGES get FLUSHed or mysql gets restarted.)

To add new access use the "GRANT" command (change the {database}, {user}, {ip}, and {password} approprately)

Code: Select all

GRANT all privileges on {database}.* to '{user}'@'{ip}'
identified by '{password}'
with grant option;
Note: the password above can be different than any other password for {user}, but it will be the password you will need to use to login from the remote system.

You will need to run that for each User/IP/Database combination you want to give remote access.

for example to give access for the nagiosql user from 10.0.0.43 with the password of "asuperstrongpasswordofyourchoicehere" use

Code: Select all

grant all privileges on nagiosql.* to 'nagiosql'@'10.0.0.43'
identified by 'asuperstrongpasswordofyourchoicehere'
with grant option;
Then for all the changes to the privileges to take effect you need to,

Code: Select all

FLUSH PRIVILEGES;
==>brian.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Remote MySQL Connection

Post by Box293 »

This document might have some helpful information as well:

http://exchange.nagios.org/directory/Do ... es/details
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Remote MySQL Connection

Post by tmcdonald »

Wow, 4 answers from 4 Nagios employees!

cchilderhose, please let us know if we have resolved your issue.
Former Nagios employee
cchilderhose
Posts: 8
Joined: Fri Apr 26, 2013 9:08 am

Re: Remote MySQL Connection

Post by cchilderhose »

Box293 wrote:This document might have some helpful information as well:

http://exchange.nagios.org/directory/Do ... es/details
This document helped tremendously. I followed the section required to create a user and open firewall. I can now access MySQL remotely. Thanks.
Locked