connection to mysql remote (local network) does not work

0

My application must be connected to MySQL that resides on a computer in my local network, with static IP.

In the connection string of my class conexion I put the IP of that computer, but it is impossible to connect.

I have my chain like this:

public static string cadenaConexion = "Server=192.168.XX.XXX; Database=XXXX; UID=XXX; Pwd=XXX; Port= 3306; ";

Will I be skipping some parameter?

Greetings to all and thanks in advance

    
asked by Nicolas Ezequiel Almonacid 14.09.2018 в 17:26
source

1 answer

0

It is very likely that they are permissions if your application worked correctly locally. You have to activate the remote access to mysql in the mysql configuration.

First you must modify the file my.cnf (the location of this depends on your operating system.We assume linux, but only change the routes, the rest is the same):

sudo nano /etc/mysql/my.cnf

and uncomment the following lines.

#bind-address           = 127.0.0.1
#skip-networking

and restart the mysql service

~ /etc/init.d/mysql restart

Then you must give the user remote access privilege ( database is the name of the base, user the DB user and password the password):

GRANT ALL PRIVILEGES
ON database.*
TO 'user'@'%'
IDENTIFIED BY 'password' WITH GRANT OPTION;

or if you want a specific ip ( 1.2.3.4 is the IP)

GRANT ALL PRIVILEGES
ON database.*
TO 'user'@'1.2.3.4'
IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

and then:

FLUSH PRIVILEGES;

To prove that it can be accessed remotely ( HOST is the IP or the domain name that we want to access and USER is the user of the BD):

mysql -h HOST -u USER -p
    
answered by 15.09.2018 / 01:01
source