Skip to content

MySQL Database Setup

Rico edited this page Sep 4, 2019 · 2 revisions

I am not a big fan of MySQL databases - that's why it took so long, until the MySQL adapter worked as it should.

While setting it up, I came across quite some issues, which I wanted to point out here. I wanted to connect to a remote MySQL database, hosted in a docker container.

Using Docker

I went the easy way and used a docker image. I thought I was able to connect to it directly after downloading, but mysql implements some security mechanisms. You first need to create a new user and add additional permissions to it, to access the database. So here are the steps I took:

1) Download and run the image
docker run --name mysql-server -e MYSQL_ROOT_PASSWORD=root --restart=always -p 0.0.0.0:3306:3306 -p 0.0.0.0:33060:33060 -d mysql/mysql-server:latest
That will create a docker container with a mysql database, which uses root as root password (please change it after setting it up).

2) Open the mysql shell inside the container
docker exec -it mysql-server mysql -uroot -p

3) Create the database
CREATE DATABASE pastepwn;

4) Create a user with which we later connect to the database
CREATE USER 'pastepwn'@'%' IDENTIFIED BY 'yourSecretPastepwnPassword';
Please change the used demo password!

5) Don't forget to give rights to the user to access the database from the outside!
GRANT ALL PRIVILEGES ON pastepwn.* TO 'pastepwn'@'%' WITH GRANT OPTION;
Attention: It's NOT recommended to grant access to the database from any IP (%). Read more about permissions here

What if I don't use docker?

Great, you are having a local installation of mysql. Login to your mysql server, then go back to the "Using Docker" section and start at 3).

Configuring pastepwn

If you setup a working mysql database, you can now go and setup pastepwn. Check out the example.py for deeper instructions.

from pastepwn import PastePwn
from pastepwn.database import MysqlDB

[...]

# You can omit the port, if you are using the default mysql port (3306)
database = MysqlDB(ip="<ip>", port=<port>, username="pastepwn", password="yourSecretPastepwnPassword")
pastepwn = PastePwn(database)

[...]

Troubleshooting

If it still does not work, try searching for your error message. Make sure there is no firewall blocking your requests. Also make sure the username and password you are using are correct.