一、先看下brew安装了哪些软件,看看是否有mysql
如果还没有安装brew,请参考这篇文章:https://www.fastjs.cn/archives/1726207293566
brew list
操作细节
uenpaydeMacBook-Pro:~ uenpay$ brew list
==> Formulae
ca-certificates mpdecimal openssl@3 readline telnet
certifi nginx pcre2 redis xz
httpie nvm python@3.13 sqlite
二、用brew安装mysql
brew install mysql
操作细节
uenpaydeMacBook-Pro:~ uenpay$ brew install mysql
==> Auto-updating Homebrew...
Adjust how often this is run with `$HOMEBREW_AUTO_UPDATE_SECS` or disable with
`$HOMEBREW_NO_AUTO_UPDATE=1`. Hide these hints with `$HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
==> Auto-updated Homebrew!
....................................
......中间安装过程省略.................
....................................
==> mysql
Upgrading from MySQL <8.4 to MySQL >9.0 requires running MySQL 8.4 first:
- brew services stop mysql
- brew install mysql@8.4
- brew services start mysql@8.4
- brew services stop mysql@8.4
- brew services start mysql
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -u root
To start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql/bin/mysqld_safe --datadir\=/usr/local/var/mysql
三、启动mysql
mysql.server start
操作细节,看到下面SUCCESS!就是启动成功了
uenpaydeMacBook-Pro:~ uenpay$ mysql.server start
Starting MySQL
... SUCCESS!
四、mysql初始化配置
mysql_secure_installation
操作细节
uenpaydeMacBook-Pro:~ uenpay$ mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test 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 component?
Press y|Y for Yes, any other key for No: N
Please set the password for root here.
New password:
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
五、启动停止mysql
brew services stop mysql
mysql.server start
操作细节
uenpaydeMacBook-Pro:~ uenpay$ brew services stop mysql
Warning: Service `mysql` is not started.
uenpaydeMacBook-Pro:~ uenpay$ mysql.server stop
Shutting down MySQL
.... SUCCESS!
uenpaydeMacBook-Pro:~ uenpay$ mysql.server start
Starting MySQL
.. SUCCESS!