1:初始化,设置密码
# 停掉mysql
brew services stop mysql@5.7
# 使用不验证的状态登陆mysql
mysqld_safe --skip-grant-tables --datadir=/usr/local/var/mysql & // 后台运行
# 启动mysql:
brew services start mysql@5.7
# 进入mysql:
mysql -u root -p
# 连接并更新密码
use mysql;
update user set password=password("new_pass") where user="root"; // 'new_pass' 这里改为你要设置的密码
delete from user where user=''; // 删除空用户
flush privileges;
quit
# 杀掉旧进程,重启服务
kill -9 进程ID
brew services start mysql@5.7
2:访问权限
# 全部权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
# 说明
格式:grant 权限 on 数据库名.表名 to 用户@登录主机 identified by “用户密码”;
grant select,update,insert,delete on . to root@192.168.1.12 identified by “root”;
3:mysql5.7 datetime 默认值为‘0000-00-00 00:00:00‘值无法创建问题解决
vim /etc/my.cnf
sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION