I've bought a server from CloudAtCost.com and all the information it gives me about my server is Server ID, IP Address, Netmask, and Gateway. I can SSH in just fine, but I can't get MySQL Workbench to connect to it. I've tried both Standard (TCP/IP) and Standard TCP/IP Over SSH.
I figured it out. I was using "user" as my username when I needed to use "root".
MySQL server needs to be running.
Network connections need to be enabled.
You need to know what port MySQL is running on (default is 3306).
If reverse DNS lookup has not been disabled, MySQL has to be able to resolve IP address to hostname.
MySQL User has to be created and assigned a password, a username and host, host is either the specific host connecting or (less secure) a '%' wildcard for host. If DNS lookups are disabled, host will be an IP address.
Connections to the MySQL port (by default it's 3306) may be "blocked" by firewall...
There are a lot of possible reasons.
When we can't connect, there's usually a MySQL error message that indicates the kind of problem encountered.
But, my preference would be to only allow IP connections from 127.0.0.1. (We always turn off reverse dns lookups on our MySQL servers.)
I'd use ssh port forwarding (tunneling). Choose a port to use on your local machine, e.g. 13306, and configure SSH to "forward" connections to that port through the ssh connection...
You can configure that in the .ssh/config for the specific remote server, e.g.
Host remoteserver
LocalForward 13306 localhost:3306
You'd need to first ssh to the remoteserver, and keep that session open.
Then on your local machine, MySQL Workbench would connect to localhost port 13306. On the MySQL server side, that will be seen as coming from IP address 127.0.0.1,
Obviously, you'd need to have a user created, e.g.
GRANT USAGE ON *.* TO myusername#'127.0.0.1' IDENTIFIED BY 'mypassword'
And grant appropriate privileges.
Go to Mysql Workbench>Server Status>Note down the port number
and give hostname as localhost:your port number,usually its 3306
Related
This may be hugely a dumb question, but I*m a novice to MySQL, and I just discovered that MySQL has different ip i.e. 127.0.0.1 and its hostname (localhost) than the machine ip which is 192.168.1.3 and machine hostname is ceres, why is it so ?
I connected to MySQL running on different machine using MySQL workbench :
and it shows it logged me to mysql root user to 127.0.0.1 on pi#192.168.1.3
then
I wanted to insert data to db remotely using arduino MCU and i can definitely not write 127.0.0.1
Every server is IP 127.0.0.1 to itself. If you want to connect to MySQL installed in a machine where you are logged in, you will use IP 127.0.0.1 or localhost but if you want to connect to MySQL on that machine via another machine, you will have to identify its IP so that you can connect via this IP. That's why remotely you will connect to your MySQL server via IP 192.168.1.3 and not on 127.0.0.1. localhost is still IP 127.0.0.1
127.0.0.1 is the loopback interface, and is used when you try to connect to the mysql service locally (on the same server where the mysql service is running).
If you need to connect to the mysql service from another machine, you will need its IP address for it. You can use ifconfig to see what IP address is assigned to the server.
You need to understand a bit about TCP/IP to follow what is going on here. Every TCP/IP stack (implementation) has the internal loopback interface under the address 127.0.0.1 (for IPv4) or ::1 (for IPv6). This makes it easy to access the stack on the local machine without knowning it's TCP/IP address (or even if it has got none).
Then each machine participating in a TCP/IP network needs an address under which it is known in this network (in your case 192.168.1.3). When you work on your local machine then it doesn't matter if you use it's public IP address or it's loopback interface. A third option is the name localhost which resolves to the loopback interface. But watch out: it depends on the OS if that ends up at the IPv4 or the IPv6 variant.
As you know you can specify a host for a user, which decides from which it can connect. And here user#localhost and user#127.0.0.1 (or user#::1) are not the same host. The MySQL terminal implicitly treats localhost and loopback IP address as the same, for the user's convenience, but other clients do not. The bind address mentioned here is usually not involved at all. This is for special scenarios not relevant here. In over 10 years I never had to set a bind address for MySQL.
Update: I hope that downvoters comment on their action to show if something needs to be improved in my answer or they are just ignorant.
When I used 127.0.0.1 as host to connect to mysql server it failed to connect
Issue : Access denied
When I used localhost as host to connect to mysql server it will able connect.
"127.0.0.1" is same as "localhost".
Also some where i read that mysql not able to
MySQL won't auto-resolve the host name
What does it mean ?
localhost is special cased and uses UNIX sockets instead of TCP/IP. 127.0.0.1 doesn't get that special handling.
See the documentation
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by using the --protocol=TCP option.
If it doesn't work when you use TCP/IP then the database probably isn't listening on the network. This is generally a good thing as it enhances security (not that listening on 127.0.0.1 exposes any problems, but listening on all interfaces gives more opportunity for attacks).
If you really want to allow connections via the network, then see skip-networking.
Assign rights to this ip then try: You can grant rights as per below;
GRANT ALL PRIVILEGES ON *.* TO 'your_user'#'127.0.0.1' IDENTIFIED BY 'your_pass';
Currently only localhost has rights but local ip does not.
If still you face problem then share the error, so that other reason can be checked if any.
Note: Assign rights as per your requirement as I mentioned all privileges just an example.
We have a MySQL server in one of the remote Virtual Machine (Windows Server 2008). Till yesterday we were able to connect to the MySQL server, with the help of workbench installed in our local machine.
Yesterday there was a restart to the machine which has the Virtual Machine installed. After that we are unable to connect to MYSQL. Though I can ping and remote connect this particular VM. I can even execute the queries inside the workbench installed in the VM.
I am not too good at networking or security related stuffs. Please help me to solve this issue.
Error :
Your connection attempt failed for user 'root' from your host to server at ABC:3306: Can't connect to MySQL server on 'ABC' (10060)
Really this could be a magnitude of possible reasons, hopefully this is a start:
Check basic network
From the MySQL virtual machine open up a command prompt and type IPCONFIG /ALL. This will show you all the IP addresses bound to different network adapters.
Check that the IP address you're connected to is listed there, the virtual machine might have got a new IP from DHCP rather than having a static IP after its restart.
Hostname vs IP
You should check the hostname resolution, from your quoted error it would suggest you are you are connecting to a hostname rather than a server IP. Check your machine can resolve to the hostname using the correct IP address - it could also be worth changing the hostname for the actual IP of the server in the connection string.
MySQL config file
You've said you're running MySQL on Windows, it was customary to rename the my.cnf to my.ini. The configuration file for older versions of MySQL previous to 4.1.5 was usually stored in either c:\my.ini or c:\windows\my.ini. For versions after this the default location is the installation directory usually %PROGRAMDATA%\MySQL\MySQL Server xxx.
When you have located the configuration file please open it on Notepad (or similar text editor), locate the [mysqld] section and make sure that port= the port you're trying to connect to and bind-address= the IP address you're trying to connect to.
Server ports
From the MySQL virtual server open a command prompt and type netstat –ano, this will show you a list of processes and what IP's / ports they are listening on. The MySQL server should be listed here and should be listening on the same port and IP as the config file defines.
Windows firewall
You should have a firewall rule to allow MySQL, the following will add one on the default port of 3306
netsh advfirewall firewall add rule name="MySQL Server" action=allow protocol=TCP dir=in localport=3306
Identify if this is machine specific
You could setup the MySQL Workbench application on another workstation and try to connect to identify if this is a global problem or just one related to your specific workstation.
mysql administrator of your database should allow remote connection to the mysql server.
change this in my.cnf:
bind-address = 127.0.0.1 # this shoul be your mysql server ip
and comment this:
# skip-networking
Chances are that your configuration was set up for an IP that has changed. By default, mysql won't let you connect from remote hosts unless you explicitly give permissions for a specific user on a specific schema or a group of schemas, for example if you did something like this:
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
Maybe what you actually did was to set the grant onto your own IP address, that is the address of your local machine, and if your local machine (not the remote server) has changed it's IP address, then mysql will not let you connect unless you have the "1.2.3.4" IP address which obviously you don't have anymore if you have a dynamic IP address (common with DSL/Cable connections)
So connect through SSH or Telnet or whatever you use to your windows server and go to mysql as root and do this:
SELECT * from information_schema.user_privileges;
That will show you the grants on all users and how they are allowed to connect. If you don't see your local IP Address listed there or a wildcard (which would allow you to connect from any remote machine to the server) then you have to set it up like this:
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
Where USERNAME of course is your user. See that after the on there is a wildcard / dot /wildcard that means you want that user to be able to connect to any schema (database, for mysql) from any user from any network. But I'd recommend that you only do the grant for the user for the specific schema you need to connect to.
Then after that, if you actually had the right information and still can't connect than use a portscanner like nmap or something like that to do a port scan and see if mysql is:
Open and listening to external network
Running on the port that you actually want to connect through
If 1 is true, then check 2 because maybe there is a misconfiguration of the port. But if any of these 2 points do work then it sounds definitely not like a network configuration but a user setting or something else.
GRANT ALL ON *.* to user#'%' IDENTIFIED BY 'password';
this command should do the trick for all users #Gustavo Rubio has already given the proper explanation.
To ensure what ports are open run cmd in the virtual machine and type.
netstat -a
TCP 127.0.0.1:3360 Hostname:3360 LISTENING
The my.cnf is located Mysql-install-path\MySQL\MySQL Server xxx make sure you backup original before changing
Can't connect to [local] MySQL server
Testing The MySQL Server Installation on Microsoft Windows
MySQL Workbench: Manage MySQL on Windows Servers the Windows way
For the first time you need to test and make sure your connection to mysql is not blocked by the firewall.
To disable the firewall on each host in your cluster, perform the following steps on each host.
1. Save the existing iptables rule set.
iptables-save > /root/firewall.rules
2. Disable iptables.
For RHEL, CentOS, Oracle, and Debian:
chkconfig iptables off
and
/etc/init.d/iptables stop
For SLES:
chkconfig SuSEfirewall2_setup off
and
rcSuSEfirewall2 stop
For Ubuntu:
service ufw stop
https://www.cloudera.com/documentation/enterprise/5-7-x/topics/install_cdh_disable_iptables.html
Depends on your setup, but if you're using cPanel just go to RemoteMYSQL and enter your host. You can also use a wildcard. Below worked for me when I was getting the error
"Could not connect to DB server '' as user ''. port : Host '' is not
allowed to connect to this MySQL server"
On MySQL v5.6 this may be the case.
When another server communicate by advertising its hostname instead of IP address, the resolution might fails (because your user is using IP address instead of hostname for example).
So, you need to disable the following,
skip-host-cache
skip-name-resolve
Or maybe create the user with appropriate hostname (instead of IP address). You may find the hostname when establishing the connection to the remote MySQL.
I'd like to connect to MySQL (deamon is running on my VPS) via HeidiSQL. I've created new user, commented bind-adress option and when I try to connect with it via HeidiSQL, I've got an error 2003: Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10061).
What should I do?
It could be a number of factors.
See if a firewall is blocking your traffic to the other host
Can you simply ping the host from the client machine?
Can you also open a simple telnet session to the host on port 3306 ?
(If the telnet is accepted, you will probably see some characters appear and you will remain in the telnet session for a few seconds before the connection is closed. If not accepted, you will see the message Connection refused.)
There's a simple checklist for this:
Is your MySQL server bound to "localhost" only? It might be listening for connections only on 127.0.0.1 or ::1 instead of any which is usually 0.0.0.0. Try connecting on your server to your server with mysql --host=host_ip where host_ip is your network IP address. I think the default is localhost-only.
Is port 3306 firewalled? Many distributions allow only SSH by default, so you may need to open this up to your client machine. Try not to open this up to everyone on the internet as having an open MySQL port is asking for trouble. It's always best to limit access to a set of specific IPs if possible.
Can you connect via an SSH tunnel instead? This is far more secure as it means your 3306 port is properly firewalled. There are many tools for creating SSH tunnels, but the basic principle is to forward a local port of your choosing to the remote server's port 3306.
I've a question to the mySQL Workbench.
I want to connect to the mysql DB at the domain aaa.com. I write at the connection options these dates:
Hostname: www.aaa.com
Port: Which port do i have to write in?
Username: Username of the DB (which is 100% correct)
Password: Password of the DB (which is 100% correct)
Default Schema: Name of the DB (which is 100% correct)
If I click connect there is following error:
"Access denied"
Also you can ssh tunnel:
Create a new connection, select Standard TCP/IP over SSH.
For SSH host name enter your domain aaa.com (the domain you would SSH to).
For SSH username enter your SSH username, so if if you ssh test_user#aaa.com your user is test_user.
Store your SSH password or key files, which ever you use.
The Mysql hostname should be 127.0.0.1 if the mysql server is on the server you are SSH'ing to, else the IP or host name of you Mysql server.
Mysql server user - your mysqsl user.
And your Mysql server password.
This way your database isn't externally acceptable, meaning no one can trying to access it from outside your server on port 3306, but you still have access it through Workbench
Contact your web hosting company to make sure they allow remote connections first. It's disabled by some hosts. Default port will be 3306.
Generally, for security reasons, the incoming connections from external domains will be disabled. Contact your host if that is allowed.
By the way, the default port of MySQL is 3306.
If you have root access to phpMyAdmin, you can see if the port is opened using this tutorial: Install MySQL and enable remote access.