MySQL remote access on Ubuntu 16.0.4 - mysql

The followings are commands which I have executed on Ubuntu.
$ mysql -u root -p
mysql>GRANT ALL ON my_database.* TO user#'MY_REAL_IP' IDENTIFIED BY 'passwd';
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#bind-address = 127.0.0.1
$ sudo ufw enable
$ sudo ufw allow 3306
$ service mysql restart
But when I use another computer on Ubuntu to access mysql on MY_REAL_IP type:
$ mysql -u user -p -h MY_REAL_IP
Can't connect to MySQL server on 'MY_REAL_IP'
how to fix it? thx

I guess bind-address should be 0.0.0.0. If you would like to access this server with real IP address. Or, you can access MySQL with simply localhost.
Would you please change bind-address = 0.0.0.0, and restart MySQL ?
EDIT
It looks there is no network connectivity. Please find the way to connect server with port 3306. How to make sure that firewall is off?

You may misunderstand the grand command, user#host means the user can login from host, which in your case, should be another computer's ip, or just use * for all ips

Exact path on Ubuntu 16.04
/etc/mysql/mysql.conf.d/my.cnf
bind-address = 0.0.0.0
service mysql restart

Related

How to set up a default MySQL connection

I have 2 mysqld.exe, one from phpMyAdmin and one from MySQL server. I use the command line command "mysql -u root -p" to connect, how do i get this command to connect to MySQL server (port 3307) by default, instead of phpMyAdmin (port 3306). It is fine to add "-P 3307", but I only want to use the command "mysql -u root -p". This command("mysql -u root -p") used to connect to port 3307, i don't know what made it change.
How can i connect to port 3307 by default.
Edit my.cnf and add port 3307 (or the one you want to be defaulted), then restart the service and you should be good.
on my.cnf be sure to have this:
port=3307
to find my.cnf file in linux or windows bash use:
sudo find / -name "my.cnf"

Change MariaDB 10.5.5 Port

I have installed MariaDB 10.5.5 in Ubuntu 20.04 server. Right now I try to change the default port of the database to let say 12345. When I look into /etc/mysql/my.cnf and /etc/mysql/mariadb.conf.d/50-server.conf there is no port options, then I add port = 5505 inside /etc/mysql/mariadb.conf.d/50-server.conf under [mysqld], then I restart the mariadb-server using sudo systemctl restart mysql & sudo systemctl restart mariadb. But when I connect the mariadb server using mysql -uusername -p, it's just connected. The expected behavior is mysql client will reject the connection. I also try to use mysql -uusername -p -P123222, but still connected. My questions is how can I can change the port and prevent this strange behavior to happen?
Unless you don't specify a hostname, the default hostname "localhost" will be assumed, so the connection will be established via unix_socket and not via TCP/IP.
To connect via port use e.g.
mysql -h127.0.0.1 -P12345 -uusername -p
There are 2 places, at least, where you may find the
port = 3306
Make sure you are changing them all, but specifically the one under the section [mysqld]
[mysqld]
port = 3307
It is this one that tells the deamon which port to use.
My guess is you changed the one under [client]
So change both :)

Resolving Bitnami MySQL Connectivity Issues

I have setup Bitnami MySQL service on Azure. The VM is up and I am able to connect to the VM through ssh
like ssh username#HOSTNAME:
I am able to login to the mysql from the prompt like
mysql -uroot -pSOMEPASS
>
Meanwhile I am able to connect this mysql service from a remote host:
mysql -uroot -pPASS -hxxx.xxx.xx.xx
The following error is what I received
ERROr 2003 (HY000); Can't connect to MySQL Server on xxx.xxx.xx.xx
I tried commenting out the the bind-address in the /opt/bitnami/mysql/my.cnf
and tried giving the value for bind-address as 0:0:0:0 & also removing the variable.
To ensure the mysql port is up or not I gave the following comamnd
netstat -tln
tcp6 0 0 :::3306 :::* LISTEN
the above results mean port is and listening
In terms of file permission related, I entered the following ones
chmod 777 /opt/bitnami/mysql/tmp
chmod 755 /opt/bitnami/mysql/data
chown -R root:root /opt/bitnami/mysq/tmp
chown mysql:root /opt/bitnami/mysql/data/
sudo chmod 777 /opt/bitnami/mysql/tmp
sudo chmod 755 /opt/bitnami/mysql/data
sudo chown root:root /opt/bitnami/mysql/tmp
sudo chown mysql:root /opt/bitnami/mysql/data
Also added
skip-grant-tables in my.cnf
I also performed the following the query in the mysql
GRANT ALL ON . to root#'%' IDENTIFIED BY 'SOMEPASSWORD';
Any hint would be greatly appreciated. Thanks in advance
To connect to your Bitnami MySQL, follow these steps:
1.Make sure your Azure VM have a public IP address.
2.Open port 3306 to NSG inbound rules:
3.Edit the file /opt/bitnami/mysql/my.cnf and comment out this line by placing a hash(#) symbol at the beginning, save it.
#bind-address=127.0.0.1
4.At the server console, allow remote access to the MySQL database server using the MySQL command line client. Use the following command, remembering to replace PASSWORD with the application password from the first step:
/opt/bitnami/mysql/bin/mysql -u root -p -e "grant all privileges on *.* to 'root'#'%' identified by 'PASSWORD' with grant option";
5.Restart the MySQL server:
sudo /opt/bitnami/ctlscript.sh restart mysql
Now, you can remote connect to your bitnami mysql.
Here is my result:
Hope this helps.

mysql not connect from remove pc installed on Amazon EC2

I have just created one instance on Amazon EC2 for CentOs, and installed mysql on it with root user (password is blank). Then I had created another user for me to connect this instance from remote pc (my local pc). for that I had run following command on terminal one by one.
CREATE USER 'demouser'#'%' IDENTIFIED BY 'demopassword';
GRANT ALL PRIVILEGES ON *.* to 'demouser'#'%';
FLUSH PRIVILEGES;
Then I wrote following line in /etc/my.cnf under [mysqld] section
bind-address=0.0.0.0
Then restarted mysql with following command
sudo /sbin/service mysqld restart
Still, It is not allowed to connect that instance from my local pc. I don't understand what is the problem? I had checked and confirmed that rules on Amazon Security Groups are set properly. (e.g. port 3306 & 22 set to 0.0.0.0 ip address, means any ip address can connect using both ports).
Can someone saw me the mistake of mine?
Slowed
I ran following command to update ipaddress in centos terminal;
sudo iptables -I INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
and It's getting connected... !!!!

ERROR 2003 (HY000): Can't connect to MySQL server (111)

This question is related to the following questions:
Can't connect to MySQL server error 111
Trying to connect to remote MySQL host (error 2003)
I am configuring a new MySQL (5.1) server on my local machine. I need to provide remote access to the database. I did the following steps:
Comment bind-address in my.cnf:
# bind-address = 192.168.1.3
Grant privileges:
GRANT ALL PRIVILEGES ON *.* TO 'nickruiz'#'%' IDENTIFIED BY PASSWORD 'xxxx';
Set port forwarding on router (TCP and UDP, port 3306, 192.168.1.3)
Configure iptables for firewall
sudo iptables -I INPUT -p udp --dport 3306 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 3306 --syn -j ACCEPT
sudo iptables-save
Restart mysql server sudo /etc/init.d/mysql restart
When testing, I get the following:
LAN:
mysql -h 192.168.1.3 -u nickruiz -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 95
Server version: 5.1.63-0ubuntu0.11.04.1 (Ubuntu)
Remote:
mysql -h 1xx.xx.4.136 -u nickruiz -p
ERROR 2003 (HY000): Can't connect to MySQL server on '1xx.xx.4.136' (111)
Clearly there's something wrong that's preventing me from being able to use my global IP address.
Notes:
I've tried testing the remote connection on the same machine and also
via SSH from a remote machine.
I'm not sure if my ISP has given me a static IP.
Any ideas?
Update:
telnet doesn't seem to be working.
telnet 192.168.1.3 3306
Trying 192.168.1.3...
Connected to 192.168.1.3.
Escape character is '^]'.
E
5.1.63-0ubuntu0.11.04.1,0g8!:#pX;]DyY0#\)SIConnection closed by foreign host.
Please check your listenning ports with :
netstat -nat |grep :3306
If it show
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
Thats is ok for your remote connection.
But in this case i think you have
tcp 0 192.168.1.3:3306 0.0.0.0:* LISTEN
Thats is ok for your remote connection.
You should also check your firewall (iptables if you centos/redhat)
services iptables stop
for testing or use :
iptables -A input -p tcp -i eth0 --dport 3306 -m state NEW,ESTABLISHED -j ACCEPT
iptables -A output -p tcp -i eth0 --sport 3306 -m state NEW,ESTABLISHED -j ACCEPT
And another thing to check your grant permission for remote connection :
GRANT ALL ON *.* TO remoteUser#'remoteIpadress' IDENTIFIED BY 'my_password';
errno 111 is ECONNREFUSED, I suppose something is wrong with the router's DNAT.
It is also possible that your ISP is filtering that port.
Check that your remote host (i.e. the web hosting server you're trying to connect FROM) allows OUTGOING traffic on port 3306.
I saw the (100) error in this situation. I could connect from my PC/Mac, but not from my website. The MySQL instance was accessible via the internet, but my hosting company wasn't allowing my website to connect to the database on port 3306.
Once I asked my hosting company to open my web hosting account up to outgoing traffic on port 3306, my website could connect to my remote database.
/etc/mysql$ sudo nano my.cnf
Relevant portion that works for me:
#skip-networking
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = MY_IP
MY_IP can be found using ifconfig or curl -L whatismyip.org |grep blue.
Restart mysql to ensure the new config is loaded:
/etc/mysql$ sudo service mysql restart
I had the same problem trying to connect to a remote mysql db.
I fixed it by opening the firewall on the db server to allow traffic through:
sudo ufw allow mysql
if the system you use is CentOS/RedHat, and rpm is the way you install MySQL, there is no my.cnf in /etc/ folder, you could use:
#whereis mysql
#cd /usr/share/mysql/
cp -f /usr/share/mysql/my-medium.cnf /etc/my.cnf
I have got a same question like you, I use wireshark to capture my sent TCP packets, I found when I use mysql bin to connect the remote host, it connects remote's 3307 port, that's my falut in /etc/mysql/my.cnf, 3307 is another project mysql port, but I change that config in my.cnf [client] part, when I use -P option to specify 3306 port, it's OK.
i set my bind-address correctly as above but forgot to restart the mysql server (or reboot) :) face palm - so that's the source of this error for me!
Sometimes when you have special characters in password you need to wrap it in '' characters, so to connect to db you could use:
mysql -uUSER -p'pa$$w0rd'
I had the same error and this solution solved it.
I had this same error and I didn't understand but I realized that my modem was using the same port as mysql. Well, I stop apache2.service by sudo systemctl stop apache2.service and restarted the xammp, sudo /opt/lampp/lampp start
Just maybe, if you were not using a password for mysql yet you had, 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES), then you have to pass an empty string as the password
Not sure as cant see it in steps you mentioned.
Please try FLUSH PRIVILEGES [Reloads the privileges from the grant tables in the mysql database]:
flush privileges;
You need to execute it after GRANT
Hope this help!