1.安装mysql
# brew安装mysql
brew install mysql
2.启动服务
brew services start mysql
3.安全启动向导设置密码
mysql_secure_installation
Securing the MySQL server deployment.
。。。。。
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: # y表示密码长度必须要设置为8位以上
Please set the password for root here.
New password: # 给root设置密码
Re-enter new password: # 确认密码
。。。。。。
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y # 移除不用密码的那个账户
Success.
。。。。
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n # n表示允许root远程登录
。。。。。。
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y # 删除test库以及对test库的访问权限。
- Dropping 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!
或
3.使用默认免密登陆设置密码
mysql -u root
alter user 'root'@'localhost' identified with 你的密码 by 'root';
4查看.my.cnf配置文件
mysqld --help --verbose | less
brew安装的mysql必须使用brew命令,mysql.server stop不起作用
# 启动 mysql, 并设置为开机启动
brew services start mysql
# 关闭 mysql
brew services stop mysql
# 重启 mysql
brew services restart mysql