Install homebrew

Go directly to the official website to see the tutorial

Or execute the following command to install (copy from the official website

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Copy the code

Mysql installation

  • Mysql > select * from mysql;
Brew search mysql ==> Formulae automysqlbackup mysql++ [email protected] mysql-sandbox [email protected] mysqltuner mysql Mysql-client mysql-connector-c++ mysql-search-replace [email protected] ==> Casks mysql-connector-python mysql-shell mysql-utilities mysqlworkbench navicat-for-mysql sqlpro-for-mysqlCopy the code
  • Select install version 5.7 here
The brew install [email protected]Copy the code
  • Add environment variables after installation and apply them to take effect
echo 'the export PATH = "/ usr/local/opt/[email protected] / bin: $PATH"' >> ~/.zshrc

source ~/.zshrc
Copy the code

Setting mysql password

After the installation is complete, set the environment variables to set the password and run the following command

mysql_secure_installation
Copy the code

Mysql has not been started

# start mysql
mysql.server start
Copy the code

Then run mysql_secure_installation again

A command selection appears

  • The first of these is to select whether to enable the verification password strength plugin (should be so
➜ bin./mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN can be used totest passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Copy the code
  • Second set mysql password
  • The third enters the password again
  • The fourth says there is a default account whether to delete him (delete y or n
  • No whether remote connection is allowed
  • The sixth has a default test library whether to delete it
  • The seventh confirmed change is that all changes take effect this time Y

ok

Success.

All done!
Copy the code

How to start

# start
brew services run mysql
brew services start mysql
# stop
brew services stop mysql
# to restart
brew services restart mysql
Copy the code

Brew Services common commands

brew services list  View the list of services installed using BREW
brew services run formula|--all  # start service
brew services start formula|--all  Start the service and register
brew services stop formula|--all   # Stop service and cancel registration
brew services restart formula|--all  Restart the service and register
brew services cleanup  Remove unnecessary configurations of uninstalled applications
Copy the code

Mysql > delete mysql from MAC

Copy it over here

ps -ax | grep mysql
# stop and kill any MySQL processes
brew remove mysql
brew cleanup
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
# edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
# restart your computer just to ensure any MySQL processes are killed
# try to run mysql, it shouldn't work
Copy the code

This is the end of normal.

Maybe there were some problems along the way

  • Save failed startup attempt at startup plus sudo
  • If sudo does not work, mysql may not have permissions on some folders
sudo chown -R _mysql /usr/local/var/mysql
sudo chmod -R o+rwx /usr/local/var/mysql
Copy the code