What's wrong with this MySql connect string - mysql

Driver={MySQL ODBC 5.1 Driver};Server=192.168.1.103;Database=mysql;User=root; Password=;Option=3;
It works just fine when use localhost or 127.0.0.1, but not 198.168.1.100 (IP of the current machine).
MySql is part of Xampp on a Windwos machine

That depends on if MySQL is binding to 198.168.1.103 or not.
Edit:
To check how MySQL is listening, run the netstat command in a command promprt:
netstat -an | find "3306"
If it is listening on 192.168.1.103, you should see an entry with that IP in the results. If you don't, then you will need to use 127.0.0.1 or localhost for your connections, unless you want to set it up otherwise.
Reply from OP: I get this
C:\Users\me>netstat -an | find "3306"
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
TCP 127.0.0.1:3306 127.0.0.1:49973 ESTABLISHED
TCP 127.0.0.1:49973 127.0.0.1:3306 ESTABLISHED
C:\Users\me>
So you are indeed listening on all interfaces and 192.168.1.103 would be accessible. Looking over your login credentials, yes that would be the issue. You're trying to login as root, which will only have localhost network access.
Basically, when you're dealing with MySQL user permissions, you generally have a username, password, and hostname. With this in mind, the same user could require a different password to login, depending on where they are connecting from.
There is a way to make it so that root can connect through 192.168.1.103 but you should not do this! The reason is that the root user has complete access to your database. If you want to login still, you would need to create a new user, and set them as able to connect from whatever IP address the MySQL server sees the user as, in the case 192.168.1.103.

Related

Can`t connect to mysql server on X.X.X.X on Windows

As the title says I want to connect remotely to mysql and it is on windows server but I got this error message.
Cant connect to mysql server on X.X.X.X
I am tring it with HeidiSql
I have MariaDB installed.
Also I can connect to server using remote connection.
Server is running and can connect to mysql localy
What have I tried:
I located my my.ini file and checked that I dont have one of these commands:
Skip-networking
bind-address = some IP
I didnt have them there in the first place
I logged in my MariaDB terminal and granted all permisions to user using this:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'192.168.100.%'
IDENTIFIED BY 'my-new-password' WITH GRANT OPTION;
I have added port 3306 to windows firewall
I guess it is worth mentioning that I cant ping that server either
if I do
ping X.X.X.X
it returns:
Pinging X.X.X.X with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for X.X.X.X:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
I have spent many hours on forums and tried all instructions but still cant connect.
Any help would be much appreciated!
The detailed problem can be from two different causes:
First option:
MySQL is binded to 127.0.0.1 or no ip at all. Check netstat on windows cmd for locating 3306 port opened to mysql process and binded to your network LAN interface or 0.0.0.0 (not to loopback / 127.0.0.1 // ::1)
For check netstat, use netstat -a -n -o, you can see in the response the PID of the process too.
For check MySQL is working on the same machine, try to connect from local console using mysql -h 127.0.0.1 (for localhost connection) or mysql -h (your LAN IP) (If you have mysql binded only to your LAN IP address).
Second option:
If first test are OK. Maybe windows firewall is not configured correctly. Try to disable windows firewall (double check disabling it). The error response on your question are because windows firewall are active and blocking connections. When you have verified you can reach 3306 with firewall off, enable it and configure. Check always you're opening the port on the required network profile (Remember, windows firewall can have different rules for private / public connections).
For check firewall correctly configured, try to access to the 3306 port on the computer from another comp on the LAN.
If you have a huge LAN network with VLANs and similar technologies, check your routing topology. Also, remember always for initial checks, disable windows firewall. Your ping are failing because firewall are enabled.

Connect to MySQL Database Remote

I have a MySQL database on another computer and I want to be able to connect from other computers (even computers on different networks). I did the following
MySQL
CREATE USER 'username_here'#'%' IDENTIFIED BY 'password_here';
then
GRANT ALL PRIVILEGES ON *.* TO 'username_here'#'%';
FLUSH PRIVILEGES;
I also commented out bind-address in the my.ini file (I have windows)
Then in the Java application (that utilizes the MySQL database) I did
jdbc:mysql://public_ip:3306/database_name
I used my public ip address in the jdbc url.
Finally, I opened port 3306 in firewall. But I am not able to connect to the database remotely. What other things do I need to do to connect?
First of all: Do not public post your real ip address and port and also say that you opened the firewall. Perhaps hackers now find it too easy to hack, but you can not rely on that ;-).
To your problem: Perhaps you configured your mysql to listen at localhost 3306 and not to your public ip address. Please enter netstat -ltn in your shell. If there is a line
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
and none with the public host address then you only have access from inside the network. Then, you have to configure your host adress in your mysql ini file. (just replace 127.0.0.1 or localhost by your ip address.
FYI : It is a very bad idea to have a publicly open port to your database server, specially MySQL default(3306) port. You are just inviting people to try to break into your database.
To access MySQL remotely, follow below steps :
1) Comment out following lines in my.cnf file.
#bind-address = 127.0.0.1
#skip-networking
2) Restart mysql server.
net stop MySQL
net start MySQL
If you got The service name is invalid then Open task manager => Click Service button => search MySql service => Restart
Remotely connect with mysql :
mysql -h HOST -u USERNAME -pPASSWORD
You can also check the open port with nmap command :
nmap -PN Ip_address
Note : Mask your ip address in your question.
MySQL Java Connectivity :
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
Connection connection = DriverManager.getConnection("jdbc:mysql://publicIpAddress/dbName?",
sqluser,password);

How to connect to MySQL Workbench?

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

error 2003 : can't connect on '192.168.1.180' (10061)?

I am trying to log into server using -
mysql -u abc -p abc -h 192.168.1.180
But getting error -
error 2003 : can't connect on '192.168.1.180' (10061)
Please help me out how to connect.
I am using window 7 and trying to connect win xp.
i am able to ping win 7 but win 7 not able to ping me(just for information).
10061 is 'network connection refused'.
Check if mysql is actually listening with:
netstat -an | find '3306'
That line, run on the host which has mysql running on it, will tell you if mysql has an open network port. If mysql is actually externally accessible, it should return one line something like this(pardon me, I run linux so from memory..):
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
Translation..
mysql is listening on all adapters: 0.0.0.0
listening on port 3306 :3306
3306 is the default port.
I believe my.cnf has to have bind-address un-commented to enable network connections though.
Edit: so if it is listening, try getting to it from the other box without involving mysql yet:
telnet <mysqlboxip> 3306
if that fails, you have a firewall issue.
Edit: Barring a firewall issue, next guess is you have mis-configured one of your network adapters. Make sure the netmask is the same on both machines, and (without explaining networking) you don't change anything but the last number when changing the address.. For your average home network, netmask should most likely be 255.255.255.0, and ip address should be in the 192.168.(1 or 15).(2-254)
If in doubt, turn dhcp back on, and look at what your router gives you for an address/netmask with:
ipconfig -a
Most home routers reserve upper addresses for dhcp assigned, so pick a low one. Stay outside the range used by the router for dhcp basically.
To see where the machine thinks it should sending the traffic:
tracert <mysqlboxip>
An incorrect netmask or a faulty route on either box could cause the traffic destined for the other box to go out the public internet way or off into nothingness.
There shoudn't be space between -p and abc as abc is password
mysql -u abc -pabc -h 192.168.1.180
Also Check bind-address in my.cnf it should be commented and also check your firewall settings.
First you confirm this address is being ping by doing this
ping 192.168.1.180

why is mySQL connecting at any/all ports

I'm running Linux Mint and trying to connect to mySQL this way
mysql --port=3306 -u root -p
Then it prompts me for my password. This is all fine. Why is it that when I type something like this it still works....
mysql --port=1234 -u root -p
Should that not fail since there is no mySQL server running on port 1234?
The reason I am asking this is because I want to create a SSH tunnel to connect to a database on another server. Let's say the SSH tunnel will forward all my traffic from localhost:3308 to myremoteserver:3306. Since my local mySQL server is accepting my connections on all ports, I cannot actually connect to port 3308 and hit the remote server. I am still hitting my local server....
Even if my SSH tunnel options might have been wrong, I was wondering if anyone knew why I can connect to port 1234 and it still hit my local mySQL server running on 3306?
IIRC mysql connects you to a Unix socket if you are connecting to localhost. Since it does not connect you via TCP in this case, there is no port involved and the port number you give does not matter.
Edit: Not sure if this is true on all systems, but If I use 127.0.0.1 or the hostname instead of localhost, mysql connects via TCP and the port number does matter - I can connect with the correct port number only.
To force a TCP connection use --protocol=TCP.
Example:
First the SSH tunnel
ssh -L 4000:localhost:3306 server.ch
and then connect to the remote mysql server with
mysql -h localhost --port=4000 --protocol=TCP -u root -p
It will ask you for your password before it tries to connect. If you enter your password (or anything else for that matter), and let it proceed, it will respond with something like:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock'
#titanoboa, thx for this! I was having the same issue. Just to add you can actually force TCP connection even for localhost using the following
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
protocol = TCP
Cheers