mac 第一次安装mysql 5.7.12 不知道root 密码的解决办法

1.    先从系统偏好设置里 把 mysql 停掉

2.    cd /usr/local/mysql/bin     (mysql的安装目录)

3     sudo ./mysqld_safe --skip-grant-tables

5.    mysql -u root

6.    update mysql.user set authentication_string='' where user='root'; 

7.    flush privileges;

修改密码:
注意:MySQL 5.7版本中user表中的密码字段列名称变了,从password变成了authentication_string了,所以MySQL5.7之前的版本用以下命令来修改:
$ update mysql.user set password=password('123456') where user='root';
MySQL5.7之后使用以下命令来修改:
$ update mysql.user set authentication_string='' where user='root';
至此修改成功。
如果可以进入,但是随便执行一条语句依然报错(ERROR 1820 (HY000): You must SET PASSWORD before executing this statement)则按照如下再次设置密码:
$ set password for root@localhost=password('12345');
设置完之后,就可以正常建表、查询使用了。