LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-15-2014, 11:51 AM   #1
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Rep: Reputation: 32
How do I grant access to mysql server from all IP Addresses


I am hosting a mysql database server that I want accessible from every computer on the network (meaning from every ip address that it receives a request from). Google searches and references manuals don't show how to do this and I have no other choice other than to ask someone on here. I was hoping that there would be a command or a string of code to insert into the my.cnf file in order to go about doing this, if not then how do I tell mysql to grant access to the server from every ip address, every user, and every database. I have limited knowledge of mysql when it comes to network configurations. I need an answer pronto.
 
Old 11-15-2014, 12:37 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Make sure the server is not started with --skip-networking.

Then the GRANTs for each accessible database must include a suitable condition, something like '%'@'%'.

See MySQL manual for GRANT usage.
 
Old 11-17-2014, 07:55 PM   #3
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
here is the string that I used
Code:
mysql> GRANT ALL PRIVILEGES ON *.* TO '%'@'%';
I just tried to connect to it via the command line with this command
Code:
#mysql -u root@192.168.1.81 -p
Then I entered the password and I keep getting this message
Code:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 
Old 11-17-2014, 08:32 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
You did not specify use of password in the GRANT, so trying to use one will produce an error when you get to that point (but that is not the error you are seeing).

The login shown is trying to connect to the MySQL server on the local machine (with the keyboard attached) not the remote machine. Apparently the local machine does not have a MySQL server running resulting in the error that you posted.

To connect to a remote MySQL instance you must specify the target host with the -h option, and do not append the address to the user name unless it was specified that way in the GRANT.

It would be helpful if you would be explicit about which machine is which so that we don't make incorrect assumptions. Also, if you could post the my.cnf from the target machine.

Last edited by astrogeek; 11-17-2014 at 08:33 PM.
 
Old 11-17-2014, 09:20 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
I am a heavy MySQL user, but have never tried to run it wide open to the network as you want to do, so I just set up a test instance to test that with.

(I am running MariaDB on Slackware, so there may be differences with Debian, probably not with MySQL).

I found that it will not allow me to specify a wide open GRANT - it accepts it but it will not honor it.

It will work with EITHER a user name, OR an IP address, either of which may include wildcards, but must include at least one non-wildcard character or single-character wildcard.

So for your case I would suggest something like...

Code:
GRANT ALL ON *.* TO 'user'@'_%';

OR

GRANT ALL ON *.* TO '_%'@'xxx.yyy.zzz.000'
...which work on my test instance.

But...

Code:
GRANT ALL ON *.* TO '_%'@'_%'
... does not work...

You will likely still need a password to satisfy the local client, or possibly add a local GRANT to cover the network connection.

Hope this helps.

(All of the above said, I whould highly recommend that you restrict the connections by password, address and database or it will surely come back to haunt you!)
 
Old 11-18-2014, 08:27 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by baronobeefdip View Post
how do I tell mysql to grant access to the server from every ip address, every user, and every database.
You need to clarify this "access" and for what purpose. I have to ask "why"?
User access to databases? Do you know what mistakes can happen? On purpose, or by accident? This is a bad idea, IMO.

Quote:
Originally Posted by baronobeefdip View Post
here is the string that I used
Code:
mysql> GRANT ALL PRIVILEGES ON db_name.* TO '%'@'%';
That's poor form even with a missing password option. Do you really want your dbs open to the nefarious bots/scripts/and other assorted wickedness that is out there?

Good Security deems that you should create mysql "users" from known hosts and stay away from wide open grants such as the above.

Code:
GRANT ALL PRIVILEGES ON db_name.* TO 'fred'@'freds_IP' identified by 'freds_password'; flush privileges; exit;
If fred connects from 2 IPs, then fred get two grants, not "any ip".

IMO, you are courting disaster doing such wide open grants, unless it is your intent to 'trash' mysql for some 'reason'?

What if fred trashed barney's database accidentally?
What if barney's deletes the mysql database?
Again, if this is your intent, then by all means carry on, else RUN FAST AND RUN FAR.

Last edited by Habitual; 11-19-2014 at 02:16 PM. Reason: s/*.*/db_name.* on grant
 
Old 11-18-2014, 09:03 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,699

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
In addition, mysql is probably configured to only listen on localhost. Before you can access it from remote computers you need to change bind-address in my.cnf to your IP address.

bind-address=192.168.1.81

Be sure to restart mysql. If running a firewall you also need to allow mysql service or TCP port 3306. Once you grant access as stated above, using a remote PC should be as easy as:

mysql -u username –h 192.168.1.81 –p
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] can not grant access to mysql for remote users golden_boy615 Linux - General 7 06-01-2011 12:00 AM
Cannot access own public web and mail server from LAN addresses lannyr Linux - Networking 14 08-06-2009 09:09 AM
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option s Braynid Linux - Newbie 1 06-08-2006 08:14 PM
MYSQL GRANT etc etc markopolox Programming 8 09-23-2003 02:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration