mysql database allow external access from specific ip only ubuntu 16 - mysql

I would like to allow one of my mysql database access from an external, however I would like to restrict it to be access from 1 ip only. Is there any way to do so:
only apply the setting to 1 database
only allow access to that database from a specific ip
My server is ubuntu 16.
thank you!

A MySQL user can be created for a specific origin address:
CREATE USER bob#'202.1.1.3' IDENTIFIED BY 'very very secure password';
GRANT ALL ON db.* TO bob#'202.1.1.3'
Provided no other GRANTS are given to db, then the bob user from '202.1.1.2' is the only allowed user.
Its generally more secure to give a ssh tunnel access, or access on a non-standard port however. Publicly accessible database servers will have their authentication brute forced.

Related

Grant Mysql anonymous user access from other machines apart from localhost?

Mysql server allows access to anonymous user from localhost. I would like to extend this privelege to other machines as well... i.e. access to mysql_server running in machine A from mysql client from machine B using the anonymous user without any password.
I understand this is not practice and I want to do it only for certain dev purposes. Can anyone let me know how this is possible for mysql server.
The version I am using is - mysql_server 5.0.15
To allow anonymous access to any host must use % wildcard:
GRANT ALL ON your_db.* TO ''#'%';
MySQL does not support wildcards in user names, but I think is better creating a guest username:
CREATE USER 'guest'#'%';
GRANT ALL ON your_db.* TO 'guest'#'%';

Preventing WAN access to a Database

How do I prevent WAN access to a particular database in SQLyog? I am able to grant full access to particular DB's, but not able to prevent them. I have a Web APP that runs on an internal server and accesses MySQL on the same server. I have created a SQL user with my workstations IP, but I am receiving access denied from dbconnect when I run the APP from my workstation.
Thanks,
Tony Cripps
MySQL does not allow connections from anything other than what you've specified. If you want to disallow access from a particular IP or network, then that mean that you've already gone and granted access to them.
Review the CREATE USER syntax, particularly the section on specifying hostnames.
Review the user accounts that you've already created:
SELECT user, host, password FROM mysql.user;
And then re-create them as necessary.
Other than than that, if you want to completely disallow WAN access then you should be looking at your firewall settings, not MySQL.

How to remotely connect to ClearDB in an Azure Website?

I have created a free Azure Website with Wordpress on it. A ClearDB mysql database was automatically created.
I want to remote connect to the DB using something like MySQL Workbench.
I used the credentials from the "View connection strings" in the azure portal dashboard, but there is an error connecting.
I read in some post that the db itself is hosted in azure cloud and thus can not be accessed.
Have anyone managed to administrate a DB like this ?
Mostly hoster don't allow an external connection with shared hostings.
When you use an outside client, your server has to be configured to allow this external connection.
Firewall rules :
You must to set password before make this, for security improvement.
You must to update firewall and make rules to open the mysql port (3306) on the server that is running the mysql database.
Set user IP :
Add an user account or replace ip address.
Adding users :
CREATE USER 'monty'#'localhost' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'monty'#'localhost'
Replace ip address (be careful don't use this on the root user) :
RENAME USER 'user'#'ipaddress2' TO 'user'#'ipaddress2';
To allow all ip replace ip adress by %.
See more :
Security Guidelines.
How to determine if a port is open on a Windows server? or www.portcheckers.com.
Yes, it is possible to administer your ClearDB MySQL database in MySQL Workbench. I have several Azure Wordpress sites that I connect to just as you describe -- create the Azure site, view Connection Strings, type those credentials into MySQL Workbench, and voila. #Yaron, Can you be more specific about what you've tried and maybe we can troubleshoot from there?

MySQL connection for every host

I'm making a winforms app in vb.net that connects to a mysql database on my webserver to read and write data, this all works fine.
But i have to allow the users ip to remote connect to the database.
Is it possible to give everyone access to the database? The user account will not have all rights an the data isn't very important if it got lost.
The user account and connection details are hard coded.
I know this isnt secure but that doesnt really matter.
Yes, that's very well possible. In your mysql privileges table you'll have to grant a wildcard (%) host access to the user. Then in your VB.NET code simply use the address in the connectionString.
Yes, you can GRANT permissions on the database to the same user with wildcards in the host. More information here.
You can specify wildcards in the host name. For example, user_name#'%.example.com' applies to user_name for any host in the example.com domain, and user_name#'192.168.1.%' applies to user_name for any host in the 192.168.1 class C subnet.
The simple form user_name is a synonym for user_name#'%'.
That way every application connects to the database from random hosts and uses the same username/password in the connection string to authenticate, and MySQL will allow it because the host part of the permissions isn't explicitly specified.
But i have to allow the users ip to remote connect to the database.
Why?
Two other options:
1 - Expose the data as a web service. It's already on the web server...
2 - Build a web app instead of a desktop app.

Granting mysql access rights to all machines on subnet

I have a mysql instance (and schema) running on windows that I can access via a connection string based on localhost as the server.
now I want to be able to access this db from another machine on the same subnet.
If possible I would like to use a single user but allow it to access from any machine on the same subnet.
how do I setup security for this?
(I already opened the relevant firewall port)
Thanks,
Eyal
You can do it like this:
GRANT ALL PRIVILEGES ON mydb TO 'username'#'192.168.1.0/255.255.255.0';
change subnet and IP accordingly
You can also use wildcards, rather than a masks.
You can specify wildcards in the host name. For example,
user_name#'%.example.com' applies to user_name for any host in the
example.com domain, and user_name#'192.168.1.%' applies to user_name
for any host in the 192.168.1 class C subnet.
See the Account Names and Passwords section of the in the GRANT docs.