Good morning.
I have been searching for some information on how to remotely access MySQL and I have found many tutorials (some of them in Stackoverflow) but after having tried them all I still can not access.
The server where I have the database is a VPS to which I have full access, and the place from where I try to access this database is a hosting of a shared hosting.
These are the things I've done:
1) In the my.cnf file, I commented on the skip-external-locking line and added the line "bind-address = 0.0.0.0".
# The following options will be passed to all MariaDB clients
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
# Here follows entries for some specific programs
# The MariaDB server
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
#skip-external-locking <---------------------------- ESTA LINEA
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
bind-address = 0.0.0.0 <---------------------------- ESTA LINEA
# Point the following paths to different dedicated disks
#tmpdir = /tmp/
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
2) I have added a rule to the iptables list of the Firewall by typing the command "iptables-INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT" in the server console.
num pkts bytes target prot opt in out source destination
39 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306
3) I have entered phpMyAdmin as root and I have modified this account to change the name of the server to "%" and I have given it "ALL PRIVILEGES".
Nombre de usuario Nombre del servidor Contraseña Privilegios globales Conceder
root % Sí ALL PRIVILEGES Sí
4) Once all this is done and after restarting MySQL and Apache, I try to connect to the database using this php code and it does not do anything, it thinks:
$hostname_vps = "aqui la IP del VPS"; (también he probado con el dominio)
$username_vps = "root";
$password_vps = "aqui la contraseña para la cuenta root";
$database_vps = "aqui el nombre de la base de datos a la que quiero acceder";
$vps = mysql_pconnect($hostname_vps, $username_vps, $password_vps) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_vps, $vps);
This connection works if the page is hosted on the VPS so the data included here is correct. I have also tried the HeidiSQL program and the connection is successful. But if I try from the page hosted on another server nothing, there is no response.
Do I do something wrong? I do not know what else to do ...
EDITO :
In the end it turns out that the provider of the other party does not allow me to connect to a database that is not in your accommodation ...
What I've done I guess it works but with this provider I'll never know.
Thank you all for the answers, I feel the inconvenience.