Table of contents
1. Install Homebrew
1.1 Quick installation
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
Paste the above command into the terminal. The script has built-in mirroring to make Homebrew installation faster.
If you want to install from another source, please use Image Assistant to obtain the script.
For more detailed installation instructions, please click Quick Start to start the installation.
1.2 Check whether the installation is successful
brew --version
If the installation is successful, the version number of Homebrew will be output, as shown in the figure below:
2. Install MySQL through Homebrew
2.1 Search MySQL version
brew search mysql
Find the MySQL 5.7 version of Formula
2.2 Install MySQL 5.7
Once the correct formula is found, install MySQL 5.7 using the following command:
brew install [email protected]
At this point, Homebrew will download, compile, and install MySQL 5.7:
Until the following information is output, it means that MySQL 5.7 has been installed successfully:
The translation is as follows:
We have installed your MySQL database without setting a root password. To ensure security, run: ``` mysql_secure_installation ```
MySQL is configured by default to only allow local connections.
To connect, run:
mysql -uroot
[email protected] is a standalone version, which means it does not create a symlink in /opt/homebrew,
because it is an alternate version of another recipe.
If you want [email protected] first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
In order for the compiler to find [email protected], you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
To start [email protected] now and restart at login, run:
brew services start [email protected]
Or if you don't want/need the background service, just run:
/opt/homebrew/opt/[email protected]/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql
2.3 Location description
-
Configuration file path:/opt/homebrew/etc/my.cnf
-
Soft connection path: /opt/homebrew/opt/[email protected]
- Source file path:/opt/homebrew/Cellar/[email protected]
- Data path:/opt/homebrew/var/mysql
2.4 Start the MySQL service
brew services start [email protected]
After successful execution, the following results will appear:
2.5 Check service status
brew services list
After successful execution, the following results will appear:
2.6 Set environment variables
Your configuration file may be.zshrc
. I use the one automatically generated when installing Homebrew.zprofile
. All my environments are configured here. You make your own judgment based on your own circumstances.
echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zprofile
echo 'export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"' >> ~/.zprofile
echo 'export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"' >> ~/.zprofile
After successful execution, you can check whether it has been added in .zprofile:
Finally runsource ~/.zprofile
to make the configuration take effect.
2.7 Reset password
Enter the following command in the terminal and press Enter:
mysql -uroot
You can enter MySQL without a password during the first installation. If the following results appear, you can successfully enter MySQL:
Execute the following command to set the root account password: (I only use it for local development and testing, so the password is weak)
# 设置密码
SET PASSWORD = PASSWORD('ok');
# 设置用户的访问密码用不过期
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
#刷新权限
FLUSH PRIVILEGES;
The setting is successful when the following results appear:
3. Test installation
Use navicat or other tools to test:
ok, the connection is successful and you're done! ! !