1:初始化,设置密码

    1. # 停掉mysql
    2. brew services stop mysql@5.7
    3. # 使用不验证的状态登陆mysql
    4. mysqld_safe --skip-grant-tables --datadir=/usr/local/var/mysql & // 后台运行
    5. # 启动mysql:
    6. brew services start mysql@5.7
    7. # 进入mysql:
    8. mysql -u root -p
    9. # 连接并更新密码
    10. use mysql;
    11. update user set password=password("new_pass") where user="root"; // 'new_pass' 这里改为你要设置的密码
    12. delete from user where user=''; // 删除空用户
    13. flush privileges;
    14. quit
    15. # 杀掉旧进程,重启服务
    16. kill -9 进程ID
    17. brew services start mysql@5.7

    2:访问权限

    1. # 全部权限
    2. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
    3. FLUSH PRIVILEGES;
    4. # 说明
    5. 格式:grant 权限 on 数据库名.表名 to 用户@登录主机 identified by “用户密码”;
    6. 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‘值无法创建问题解决

    1. vim /etc/my.cnf
    2. sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION