Pythonanywhere: Accessing the MySQL database

The objective of this post is to explain how to access the MySQL database of a free Pythonanywhere account and perform some simple tests.


The objective of this post is to explain how to access the MySQL database of a free Pythonanywhere account and perform some simple tests.

Fortunately, MySQL is almost ready to use when we create an account on Pythonanywhere. Basically, we only need to set the database password and the database name, as we will see bellow.

We don’t need to install any software on our local machine since Pythonanywhere provides us with a web browser based command line to interact with the database.

Configuration of the database

First, we login to our account and go to the databases tab. On the first time we access it, it will ask for a password. Choose your database’s password. You will need to remember it later if accessing the database from a Python program hosted in Pythonanywhere.

After setting the password, you should be presented with a configuration page similar to the one in figure 1.

Python anywhere db tab configuration.png

Figure 1 – Databases tab.

The first highlighted section (“Connecting” separator) corresponds to the information details needed to connect to the SQL server associated with your account [1]. So, if we wan’t to access the database from a Python program, this section has the settings needed.

In my case, I already have some databases created, but let’s create a new one. To do so, in the second highlighted area (“Database name” separator) introduce the database name sqlTest and click the create button.

As indicated in figure 2, the new database should now appear on the “Your database” separator. Note that the Pythonanywhere automatically added a YourUsername$ prefix to the database name.


Figure 2 – New database created.

Now, to open a console to interact with the database, just click on it’s name. A web console should now appear, as shown in figure 3.


Figure 3 – Database web console.

We can now test some commands. Send the following command to list all the databases on the server:

show databases;

You should get something similar to figure 4. In my case, all the databases I have configured are shown.


Figure 4 – Output of the show databases command.

To clear all the content on the command line, just type the following command:

system clear

You can also print the time and date with the following command:

select now();

You should get the current time and date, as shown in figure 5.


Figure 5 – Current time and date.

Final notes

As seen by this tutorial, starting to work with a MySQL database on the Pythonanywhere environment is very simple. So, for a free account, we not only have the possibility to develop an application with a framework such as Flask, but now we also have access to a database.

Related posts



Leave a Reply