Search code examples
pythonmysqldjangoapipythonanywhere

How to make my Django API public, which is connected to MYSQL database?


The problem is I have connected my Django API to MYSQL workbench, but it is only accessible in my localhost. Methods I have tried:

  1. Forwarding a port and running my server with "python manage.py runserver 0.0.0.0:3000".
  2. I hosted my Django API in PythonAnywhere. Now my API became public, but I could not connect my Django API with MYSQL workbench

Please help me with it. Thanks in advance


Solution

  • firstly give access to mysql port 3306 from firewall, means create inbound rule for private and network.

    if you are using windows,

    go to firewall advance settings,

    create a new inbound rule with port 3306,

    give access to private network for now.

    then create user in mysql and give access to your 0.0.0.0 ip by using this command:

    CREATE USER 'newuser'@'0.0.0.0' IDENTIFIED BY 'password';
    

    or

    CREATE USER 'newuser'@'<your ipv4 address>' IDENTIFIED BY 'password';
    

    now you can get access from your machine and other into the mysql.

    and i don't know how to give access in ubuntu.