0

I would like to host a database on my raspberry pi to which I can access from any device. I would like to access the contents of the database using python.

What I've done so far:

  1. I installed the necessary mysql packages, including apache 2.
  2. I created my first database which I named test.
  3. I wrote a simple php script that connects and displays all the contents of my simple database. The script is located on the raspberry pi at /var/www/html and is executed when I enter the following from my laptop (192.168.3.14/select.php)

Now my goal is to be able to connect to the database using python from my laptop. But I seem to have an error connecting to it, this is what I wrote to connect to it.

db = MySQLdb.connect("192.168.3.14","root","12345","test" )

Any help or direction is appreciated.

Bonavia
  • 55
  • 2
  • 5

3 Answers3

1

on the terminal of your raspi use the following command: mysql -u -p -h --port

where you switch out your hostname with your ip address. since currently you can only connect via local host

0

at first step is check you haven't firewall rules on raspberry or in your lattop

after you can try this command on mysql

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

and remember to apply new privileges

FLUSH PRIVILEGES;

for more detail you can see https://dev.mysql.com/doc/refman/5.7/en/grant.html

is similar for mariadb ecc...

Mattia Moscheni
  • 144
  • 1
  • 2
0

The reason why you are not able to connect to the database from outside of localhost is that the remote access for the root user is prohibited by default, i.e. you can only access the database with the root user from localhost. You can, however, change this by tweaking root's privileges. Please take a look here to find out how the user privileges need to be change to make this work.

m_____z
  • 1,521
  • 13
  • 22