S
S
Sergey Gladyshev2019-09-03 20:33:31
MySQL
Sergey Gladyshev, 2019-09-03 20:33:31

How to connect to mysql on Vagrant from a remote server?

I want to connect to Vagrant mysql from a Python application

@app.route('/api', methods=['GET', 'POST'])
def main():
    if request.method == 'GET':
        db = pymysql.connect("188.168.61.34:3306", "root", "", "dejavu")
        cursor = db.cursor()
        cursor.execute("SELECT VERSION()")
        data = cursor.fetchone()
        print("Database version : %s " % data)
        db.close()

But I am getting the following error
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '192.168.56.1:3306' ([Errno -2] Name or service not known)")

mysql set up according to this instruction
Here are my steps:
sudo apt-get update sudo apt-get install build-essential zlib1g-dev git-core sqlite3 libsqlite3-dev sudo aptitude install mysql-server mysql-client

sudo nano /etc/mysql/my.cnf change: bind-address = 0.0.0.0

mysql -u root -p

use mysql GRANT ALL PRIVILEGES ON . to [email protected]'%' WITH GRANT OPTION; FLUSH PRIVILEGES; exit

sudo /etc/init.d/mysql restart

My Vagrantfile
I also did the following on the machine running vagrant:
Set up dynamic dns in router settings
dur9otxyd2ss7u4v9bvaupocnjo.png

Set up port forwarding
i3wykyhbicfzsiu9-yamqraeqak.png
(according to instructions )
Installed Dynamic Update Client
Looked at public ip

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Karasik, 2019-09-03
@vitaly_il1

1) Maybe something is messed up with the network.
Check the private network and virtual machine address match.
2) Or MySQL did not start on the virtual machine. Log into the console and check that MySQL is running.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question