MacOS M chip installation MySQL5.7 tutorial


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.
Insert image description here

For more detailed installation instructions, please click Quick Start to start the installation.

Insert image description here

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:

Insert image description here

2. Install MySQL through Homebrew

2.1 Search MySQL version

brew search mysql

Insert image description here
Find the MySQL 5.7 version of Formula

Insert image description here

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:

Insert image description here
Until the following information is output, it means that MySQL 5.7 has been installed successfully:

Insert image description here

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
    Insert image description here
    Insert image description here

  • Soft connection path: /opt/homebrew/opt/[email protected]

Insert image description here

Insert image description here

  • Data path:/opt/homebrew/var/mysql

Insert image description here

2.4 Start the MySQL service

brew services start [email protected]

After successful execution, the following results will appear:
Insert image description here

2.5 Check service status

brew services list

After successful execution, the following results will appear:
Insert image description here
Insert image description here

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:

Insert image description here

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:

Insert image description here
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:
Insert image description here

3. Test installation

Use navicat or other tools to test:

Insert image description here

ok, the connection is successful and you're done! ! !

Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_52799373/article/details/134778815