[Macro Example] Use Python to Interact with MySQL (v9.2)

Author :⠀ Martin Zhang
Created :⠀ 03/28/2021, 237 PM ET
Modified :⠀
Version :⠀ 1.0
Purpose :⠀ Use Python3 and the PyMySQL module to interact with MySQL.
Comments :
  • Make sure MySQL is running.

  • The Python code uses Python3.

    • You may need to change: #!/usr/bin/python3 for other versions.
  • The Python code utilizes the PyMySQL module.

    • You will need to install this module if it's not already available on your system.
    • To install, run the command in the Terminal: pip3 install PyMySQL
  • In my case the PyMySQL module is installed at:

    • /usr/local/lib/python3.9/site-packages/
    • You may need to change the path on your system /YourSystemPath/../pymysql
  • The entries in each row are connected by a space. (You may use other text delimiters.)

    • Edit the space between the single-quotes in print(' '.join(map(str, row)))
  • Set the database Name, User, Password, and the Command in the KM variables (orange color).

DownloadMySQL - Python.kmmacros (8.7 KB)


If you don't want to put the password there, you may use

to place

To do this, you need first save the password in the keychain. For instructions, see
Set and Get a Keychain Password - Macro Library - Keyboard Maestro Discourse