I have a server with Rackspace. I want to access the database from my local machine command line.
I tried like:
mysql -u username -h my.application.com
If you want to not use ssh tunnel, in my.cnf or mysqld.cnf you must change 127.0.0.1 with your local ip address (192.168.1.100) in order to have access over the Lan. example bellow:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Search for bind-address in my.cnf or mysqld.cnf
bind-address = 127.0.0.1
and change 127.0.0.1 to 192.168.1.100 ( local ip address )
bind-address = 192.168.1.100
To apply the change you made, must restart mysql server using next command.
sudo /etc/init.d/mysql restart
Modify user root for lan acces ( run the query's bellow in remote server that you want to have access )
root@192.168.1.100:~$ mysql -u root -p
..
CREATE USER 'root'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
If you want to have access only from specific ip address , change 'root'@'%' to 'root'@'( ip address or hostname)'
CREATE USER 'root'@'192.168.1.100' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Then you can connect:
nobus@xray:~$ mysql -h 192.168.1.100 -u root -p
tested on ubuntu 18.04 server
try telnet 3306
. If it doesn't open connection, either there is a firewall setting or the server isn't listening (or doesn't work).
run netstat -an
on server to see if server is up.
It's possible that you don't allow remote connections.
See http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
Must check whether incoming access to port 3306 is block or not by the firewall.
edit my.cnf file:
vi /etc/my.cnf
:
make sure that:
bind-address=YOUR-SERVER-IP
and if you have the line:
skip-networking
make sure to comment it:
#skip-networking
don't forget to restart:
/etc/init.d/mysqld restart
Try this command mysql -uuser -hhostname -PPORT -ppassword
.
I faced a similar situation and later when mysql port for host was entered with the command, it was solved.
Try this, Its working:
mysql -h {hostname} -u{username} -p{password} -N -e "{query to execute}"