Connecting to MySQL from Python in MacOS is a very problematic and painful process;

And I should not use the mirror homebrew source in China:

Mac OS

/bin/bash -c "$(curl -fsSL \
<https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"

brew install mysql
mysql_secure_installation  # setup the credentials in MySQL server

# choose one way to start
brew services start mysql  # background
mysql.server start

# connector
brew install mysql-connector-c

# openSSL
brew install openssl # it may already installed
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

# unlink mysql and link mysql-connector-c before pip install, then restore
brew unlink mysql
brew link --overwrite mysql-connector-c --force
pip install mysqlclient
brew unlink mysql-connector-c
brew link --overwrite mysql

# the above should be done every time when using virtual env
# unless use --system-site-packages if you've installed it globally
python3 -m venv venv_name --system-site-packages

Linux

sudo apt-get install mysql-server
sudo apt-get install libmysqlclient-dev
sudo apt-get install python3-dev

pip install mysql
pip install mysql-connector

Trouble Shooting