PI_newbee
Posts: 169
Joined: Mon Aug 26, 2013 7:41 pm

Mysql --> installed and running, but i can not connect

Wed May 24, 2017 9:09 am

Hi to all.

I have mysql on rsp located on ip adress 192.168.1.15.
I can access it, create table and do all the stuff but i can not access it from another computer in the same network.
There is a program on that other PC which should connect to db on rsp but each time i want to connect i get error in connection.
Any ideas ?

https://ibb.co/fBup3F

btw. in the code, conection to db is set as -localhost-. and i can connect it like i written before.
If i change it to 192.168.1.15 , then i can not connect to local RSP, mysql service...

achrn
Posts: 376
Joined: Wed Feb 13, 2013 1:22 pm

Re: Mysql --> installed and running, but i can not connect

Wed May 24, 2017 12:16 pm

Mysql has its own user permissions system. Have you set up the users table to allow the connection? The permission system distinguishes between both the user and the connecting machine, that is, a user who can connect locally cannot necessarily connect from a remote machine.

Connect locally then do 'select * from mysql.user;'

If that doesn't mean anything to you do some googling along the lines of 'mysql user table'.

User avatar
rpdom
Posts: 15431
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Mysql --> installed and running, but i can not connect

Wed May 24, 2017 6:34 pm

By default, MySQL only listens on the local IP address 127.0.0.1 or a socket file. To make it available to your network you need to change the config.

I create a file called /etc/mysql/conf.d/local.cnf with the contents

Code: Select all

# Local mysql config file

[mysqld]
# Allow listening on all IPV4 addresses
bind-address = 0.0.0.0
That will allow access from anywhere, so make sure your firewall/router doesn't allow port 3306 from outside your network.

digitalForest
Posts: 7
Joined: Sat Jun 01, 2013 10:19 am

Re: Mysql --> installed and running, but i can not connect

Thu May 25, 2017 9:30 am

Both answers are correct.

In my experience however, you have to balance security with access rights. So exposing port 3306 to everyone is a bad choice. The best way is to SSH into the RPi and then access the MySQL db via localhost on port 3306.

Btw, consider using MySQL Workbench as a graphical UI to modify User access, data structure, etc.

Return to “General discussion”