title: How do I connect to a MySQL Database in Python with a RaspberryPi
body: <p>I'm a student and I'm trying to write some sensor values into a MySQL database.</p>
  <p>As IDE I'll be using Inteliji.
  First off I started by installing the database Plug-in.</p>
  <ul>
  <li>This was done successfully</li>
  </ul>
  <p>Next I tried to connect to the data base (see figure below)</p>
  <p><a href="https://i.stack.imgur.com/MubFi.png" rel="nofollow noreferrer">Figure of successful connection</a></p>
  <p>Now The next thing I want to do is use a MySQL connector.
  Therefore I've installed MySQL onto the r-PI and used following code to implement it.</p>
  <pre><code>import mysql.connector
  print(&quot;Step 1&quot;)
  cnx = mysql.connector.connect(user='a21ib2a01', 
                                password='secret',
                                host='mysql.studev.groept.be',
                                database='a21ib2a01')
  Print(&quot;Step 2&quot;)
  </code></pre>
  <p>When now I run my code the terminal will output:</p>
  <pre><code>Step1
  </code></pre>
  <p>For some reason I don't know; the connect function always times my program out with the next occurring errors:</p>
  <pre><code>mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'mysql.studev.groept.be:3306' (110 Connection timed out)
  </code></pre>
  <p>So does anyone know why my connection is successful but I can't connect to it?
  Long story short what am I doing wrong and how do I fix this?</p>
  <p>Thanks in advance!</p>