MySQL TCP Connection - mysql

I have a MySQL Database which I want to connect to from a different computer, preferably using TCP/IP. What is the easiest way to do this. Currently I have tried just putting the IP address of the computer in, and it comes up with Error #1130, which is no help.
Any nice easy ways to do this?

Make sure "skip-networking" is not in your my.cnf file (restart MySQL if it is after changing it), and that you've created a user with permissions to connection from your remote host. Something like:
GRANT SELECT,INSERT,UPDATE,DELETE ON mydb.mytable TO "myuser"#"myotherhost" IDENTIFIED BY "somepassword";

Related

Granting Access to a User from a Remote Machine - MYSQL

I have a database in mysql and I would like to grant access to a user from a remote machine. How can this be achieved?
Thanks
Usually first thing you need to do is comment bind-address in MySql config file (my.cnf). This settings is blocking communication with database if it's not from the the same address, and restart mysql to apply changes. Also don't forget to open port 3306 on which MySql communicate.
Next you can freely create a new database user, which login will be #'%'.
But beware, if it's a production server, it is not good practice to do this, it is security hole which can be used.

MySQL Workbench & Google Compute Engine Connection

I have mysql installed in an instance of google compute engine. I am able to connect to it via the shell however I want to use the MySQL workbench.
Is it possible to connect to it? I cant seem to make a connection.
Any help is appreciated,
Thanks!
Not sure if your shell is run local on host via ssh, so it's just a guess that your mysql Server is just accepting connections from localhost.
To change this open your my.cnf File (on Debian Systems saved in /etc/mysql/my.cnf) and comment the folloing Line:
change:
bind-address =127.0.0.1
to:
#bind-address =127.0.0.1
Be sure also to allow root connection from outside, modifying MySQL user table :
GRANT ALL PRIVILEGES ON . TO 'root'#'%' IDENTIFIED BY 'password';
SOehl's answer can be correct, however I did not comment. Instead i changed it to bind-address 0.0.0.0.

determining the IP from which an mysql connect (PDO) request came from

I want one Linux server to get or put data to the MySQL server on another Linux machine. I want to avoid granting
GRANT ALL PRIVILEGES ON *.* TO root#% IDENTIFIED BY 'password';
but instead would like to do:
GRANT ALL PRIVILEGES ON *.* to root#123.123.123.123 ..
where 123.. is the IP of the server that is making the request. Where would I go to get a log of the request made on the receiving database end, to know what IP is being queried from? I don't know enough about networking to know this, or to be sure which IP is being used.
Also, would it be OK to use a hostname of the querying server, or is that slower due to DNS lookup time?
If you want to know what IP you're connecting from:
SHOW PROCESSLIST
This will show the originating IP. You can tighten your rules accordingly.
As per my comment to #tadman, the problem turned out to be that I had
bind = 127.0.0.1
in the my.conf file found in /etc/mysql.
Well, once I disabled and restarted mysql, mysql came back and said "permission denied to root#____" - but then I was able to know the IP address. Predictably I guess, it was the primary DNS IP for that server. But problem solved because I was able to set that permission on the remote.

MySql database allow remote connections

I am using a synology 713+ nas server, and just started using MySQL with it.
I created a database, a table and a user with '%' as host, so it should be able to connect from anywhere.
Using the local ip to the nas-server, I am able to connect to the database without a problem. But when I try using the external ip, I get the following message instantly;
'Unable to connect to any of the specified MySQL hosts.'
In the 'my.cnf' file, I have disabled 'skip-networking' and set 'bind-address' to 0.0.0.0.
I am unable to see the 'bind-address' variable in phpMyAdmin, so I am unsure if it is actually using it.
If I try to connect while the database is offline, I times out after 30 seconds, but when it is online it refuses instantly, which tells me that it is able to find the server, but not allowed to connect.
What in the world is going on, and what can I do?
Edit:
All ports on the nas are open, and my router is forwarding port 3306 to the nas.
Restarting mysql and the whole nas did not work.
I suspect the 'bind-address' variable is not being used...
I had a similar problem and I solved it this way:
Try to create a new user from sql command of phpmyadmin like this:
CREATE USER 'myuser'#'%' IDENTIFIED BY 'mypassword'; GRANT ALL ON *.* to myuser;
and use this user for the connection.
MariaDB 10 default port is 3307

Access remote MySQL server without editing my.conf

I want to connect my Django app (hosted on a VPS) to a database hosted on another server with more memory, so I can run stuff and add things to the database without the risk of it getting killed for using too much memory on my VPS. The things I've seen about this (e.g., How to connect to MySQL server on another host?) all involve editing my.cnf and changing the bind-address line. I a)don't have root privileges to do this, and b)don't want to expose other users' MySQL dbs to potential security risks. I tried editing ~/.my.cnf to change the bind-address thing, but that doesn't seem to work.
I also found http://www.rackspace.com/knowledge_center/article/mysql-connect-to-your-database-remotely, which suggests creating 'user'#'remote-ip-address' and then granting that user permissions. I tried that, but I keep getting ERROR 2003 (HY000): Can't connect to MySQL server on '(the server's address)' (110) when I try mysql -u username -p -h (the server's address).
I have access to the root user for MySQL, but no other admin privileges on the server where I want to set up the database. Is there any way to configure things so Django can access this remote db without directly editing /etc/mysql/my.cnf?
The bind-address doesn't specify which IPs can connect to that server, but which address is MySQL listening to. So, just set it to 0.0.0.0 and it will work. Please make sure you've got a user account with that address. Check mysql.user table.
Addressing the root-access thing:
* If you installed mysql manually, you've got root access.
* If you didn't install mysql manually, but it's a service provided by the VPS hosting, then the bind-address should be 0.0.0.0 (or at least not 127.0.0.1). If it's not the case, contact them because they're screwing up pretty bad.
Hope it helps.
EDIT, CLARIFICATION:
MySQL bind-address is not a security constraint. If you want to allow some addresses to connect to the server you should create/grant users with the that address specified, like this
CREATE USER 'bobdole'#'192.168.10.221';
Rather hacky, but I think this should be possible with MySQL Proxy listening on an unprivileged port on the public IP, proxying all queries to the mysqld which is running locally.