Nothing is more sad then a Mautic Contact page with missing little colorful flags. It just doesn’t look organized.

And the worst is: all this information needed to populate the country, city, state data is already available in Mautic. This happens if Mautic starts to collect data before the Maxmind database is installed. Once the setup is done, and ip is being matched, the state / city / country information will be available, and all the nice flags will appear.

But what can we do retrospectively if we’d like to populate this data?

I created a little shell script, that loops through all the missing contact information, taps into the Maxmind DB and makes your Mautic database complete again. It even fills out your postcode.

1. Go to the Mautic folder (or any folder here you keep shell scripts)

2. Create a file


3. Copy in the content
4. The script will use your Maxmind and your Database credentials based on your Mautic config. You don’t need to add it one more time. Just make sure you have the right Mautic path defined:


4. Make it executable

chmod +x

5. That’s it, you can run it now. It will populate all the missing country, state and city information.


The results should look like this:

2023.03.05. Update:

Thanks to Sebastian Fahrenkrog, there is an update to this script. Additions:

– Using and fix the things I he with escaping
– Adapt the sql query to skip ip addresses with wildcards (anonymized ips) and local addresses
– change the error handling in the mmdlookup tool (skip errors while lookup ip)
– make it the updates more incremental (sometimes only country is present .. )
– suppress mysql warnings
– change the way the mysql queries are done

Thank you so much Sebastian 🙂 for feeding this back to me.

In order to download the commented code, you need to register for free. If you already registered, log in here

2 Comment

  • Mike


    Hi Joey,

    As per my last post here, this is a great and super helpful script!! Thanks again.

    I have been trying to query the mmdb in order to get state and am totally stumped.

    Is there anyway you would look at trying to extract state from the DB as well ?
    (GeoLite2-City.mmdb –ip subdivisions.0.names.en)


Leave a Reply

Your email address will not be published. Required fields are marked *