安装

# 使用 homebrew 安装
brew install mysql

# 初始化,根据提示填写
mysql_secure_installation

# 启动
brew services start mysql

# 关闭 
brew services stop mysql

# 登录
mysql -u root -p

# 退出
quit

使用

常用命令

show databases; # 查看所有数据库
show tables; # 查看当前数据库中的所有表

其他

TODO。

常见问题

问题1: Authentication plugin ‘caching_sha2_password’ cannot be loaded

mysql -u root -p
# 输入密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; # 修改加密规则(password需要替换成你的密码,下同)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; # 更新一下用户的密码
mysql>FLUSH PRIVILEGES; # 刷新权限

如果一直提示 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,输入:

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.02 sec)

密码中必须含有数字、字母、特殊字符(比如#@等),且不小于 8 位。

参考