While trying to build a service around a local LLM agent, I ended up installing MySQL again for the first time in a while. The policy changes since 8.x mattered, the version left on my machine was far too old, and even after looking back through an earlier post I had written (Old-school MySQL), I eventually decided to stop hesitating and reorganize the whole process quickly from scratch.
Old-school MySQL Introduction - Prologue
My LattePanda home server has been acting up lately. Rather than wasting time only patching it, I decided this was the moment to finally get into MySQL properly. The reference book was SQL for Beginners...
normalstory.tistory.com
The order of this guide is simple. First check whether MySQL is already installed. Then remove the ambiguous leftover installation as completely and thoroughly as possible, and reinstall it. For reference, if you want to use MySQL Workbench for easy CSV import, then as of 2024 you should install MySQL 8.0.xx.
Environment check
- Check whether it is installed which mysql
- Check the version mysql --version
- Check whether it is active
- brew list | grep mysql
- brew services list | grep mysql
- sudo mysql.server status
Completely remove MySQL (macOS)
- Kill the MySQL process
- Case 1: if installed through Homebrew brew services stop mysql
- Case 2: if registered through launchctl sudo launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
- Delete related files
- Check the installation path which mysql
- Remove via Homebrew brew uninstall --force mysql
- Or
- brew uninstall mysql --ignore-dependencies
- brew remove mysql
- brew cleanup
- Then enter and remove the following lines one by one.
sudo rm -rf /usr/local/mysql
sudo rm -rf /usr/local/bin/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/Cellar/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /tmp/mysql.sock.lock
sudo rm -rf /tmp/mysqlx.sock.lock
sudo rm -rf /tmp/mysql.sock
sudo rm -rf /tmp/mysqlx.sock
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
Install MySQL
- Install the package brew install mysql@8.0 (*for MySQL Workbench compatibility)
- Start the server mysql.server start
- Set the root password mysql_secure_installation
- Stop the running server mysql.server stop
Environment setup
- Check your machine's default shell
- echo $SHELL
- => (result) /bin/zsh
- On macOS, the default shell changed from Bash to Zsh starting with Catalina. So if you are using a recent macOS version, Zsh is likely already your default.
- echo $SHELL
- Add the path - nano ~/.zshrc
- Add export PATH="/usr/local/mysql-8.0.37-macos14-arm64/bin:$PATH"
- `mysql-8.0.37-macos14-arm64` can vary from machine to machine. Usually it is cleaner to write just `mysql`.
- => (to exit) :wq
- Add export PATH="/usr/local/mysql-8.0.37-macos14-arm64/bin:$PATH"
- Know the difference between shell startup files
Login shell When logging into the system
(terminal login, SSH, etc.)~/.zprofile (Zsh),
~/.bash_profile (Bash)Initial setup
(environment variables, system-wide settings)Interactive shell Opening a new terminal tab or window,
or starting a shell inside an already logged-in session~/.zshrc (Zsh),
~/.bashrc (Bash)Daily command input, aliases, functions, and so on
Using MySQL
- CLI : terminal-based usage
- mysql -u root -p
- After `-u`, enter the account you want to connect with. Here we will test logging in as the `root` user we just configured.
- `-p` means you will connect using a password.
- => (to exit) exit
- GUI : tools-based usage
- qstudio : AI SQL
- https://www.timestored.com/qstudio/database/mysql
- https://www.timestored.com/qstudio/download
- (after moving into the file folder) java -jar qstudio.jar
- MySQL Workbench : CSV import
- DBeaver
- qstudio : AI SQL
Options
- Start automatically on reboot brew services start mysql
- Stop automatic startup on reboot brew services stop mysql
