mac下安装Mysql5.7遇到默认密码的大坑


我本身是有丰富的centos下Mysql5.7的安装经验的,也有mac下使用brew安装5.6的经验,但没在mac下装过5.7这高版本经验…  

文章写的不是很严谨,欢迎来喷,另外该文后续有更新的,请到原文地址查看更新。

http://xiaorui.cc/2016/01/20/mac%E4%B8%8B%E5%AE%89%E8%A3%85mysql5-7%E9%81%87%E5%88%B0%E9%BB%98%E8%AE%A4%E5%AF%86%E7%A0%81%E7%9A%84%E5%A4%A7%E5%9D%91/


安装的过程很简单,就直接到官方下mysql dmg,一路下一步就可以装完..  

Mac Mysql dmg下载地址,http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.10-osx10.10-x86_64.dmg

但是带来的问题是,默认密码不为空… mysql -uroot -p 登陆不进去… 直接使用mysqladmin改密码也提示错误.


一般在centos下安装Mysql 5.7版本后,密码应该是放在 ~/.mysql_secret文件里,但是Mac呢 ?各翻遍了所有目录都没找到… 一顿狂Google之后,发现不少老外也在纠结这个问题…   这算不算个坑…

#blog: xiaorui.cc

[root@devops ~ ]sudo find / -name ".mysql_secret"
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory

[root@devops ~ ] ll /private/var/root/.
total 24
-rw-------   1 root  wheel  2520 11 10 23:31 .sh_history
-rw-------   1 root  wheel  3402 11 10 23:31 .viminfo
drwx------  13 root  wheel   442  9 10 22:23 Library
-rw-r--r--   1 root  wheel     5  1 16  2015 .CFUserTextEncoding
-r--r--r--   1 root  wheel    10  9 10  2014 .forward

那么密码跑哪里去了?  不纠结了,直接把默认密码干掉,再重新配置一个新密码. 

首先我们通过 –skip-grant-tables的方式启动mysqld_safe进程 ,这个模式是可以绕过mysql授权.

#xiaorui.cc
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

mysql5.7颠覆的事情太多了,已经mysql.user会有个password字段,现在替换成authentication_string了. 

| authentication_string  | text                              | YES  |     | NULL                  |       |
| password_expired       | enum('N','Y')                     | NO   |     | N                     |       |
| password_last_changed  | timestamp                         | YES  |     | NULL                  |       |
| password_lifetime      | smallint(5) unsigned              | YES  |     | NULL                  |       |
| account_locked         | enum('N','Y')                     | NO   |     | N                     |       |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+

然后正式改密码,注意姿势 !

#xiaorui.cc
mysql> update mysql.user set authentication_string=PASSWORD('123123') where user='root';
Query OK, 1 row affected, 1 warning (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql>

这时候Myqsl密码已经修改完了,我们把上面的mysqld进程干掉,通过正常途径起Mysqld服务

mysql -uroot -p

mysql>
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
mysql> set password for root@localhost=password('123123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql>


当你通过skip授权修改的密码,需要再次修改下密码. 也不知道为什么有这个要求,闲的.

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


这样Mysql的密码改完了, 另外我已经给Mysql发了一个邮件说明了这个问题,不知道他们是否会给予回复.  

  


大家觉得文章对你有些作用! 如果想赏钱,可以用微信扫描下面的二维码,感谢!
另外再次标注博客原地址  xiaorui.cc

12 Responses

  1. violorch 2016年6月18日 / 下午5:00

    5.7 的密码字段authentication_string是加密过的字段,直接修改是木有用的

  2. clover 2016年6月5日 / 下午4:13

    在安装完成之后会弹出一个对话框 2016-06-05T08:11:22.301534Z 1 [Note] A temporary password is generated for root@localhost: kw=Rg!9C_Gsi ,告诉你初始密码了。

    • wpf 2016年6月16日 / 上午9:45

      哥们,为啥我没有看见啊 就是直接装完以后吗?

    • wpf 2016年6月16日 / 上午9:46

      这个问题已经纠结几天了。我是苹果电脑小白 真是无语啊

    • Guest 2016年7月9日 / 下午2:20

      哥们,然而我执行./mysqladmin –u root –p password的时候,输入这个临时密码之后。 一直提示Access denied for user ‘root’@’localhost’ (using password:YES) 。这是什么情况?

      • rfyiamcool 2016年7月9日 / 下午4:00

        需要重复我上面的步骤的,暂时没找到好的方法。 另外有网络说在日志里,我是没找到.

  3. 黄祺 2016年4月20日 / 上午9:09

    怎么查看启动日志啊?

  4. mysql 2016年3月20日 / 下午8:58

    赞,找了这么多文章,就你的靠谱!!!

  5. 123 2016年3月19日 / 下午8:30

    …为什么用你的方法连mysql都开不了了

  6. 默认密码在mysql启动日志里面 2016年1月23日 / 下午10:10

    默认密码在mysql启动日志里面。。。

    • clausewitzer 2016年4月9日 / 下午4:52

      正解 在mysqld.log 里面会用 一条类似的
      2016-04-09T08:40:45.611889Z 1 [Note] A temporary password is generated for root@localhost: Mj0Hx4_i.Otj

mysql进行回复 取消回复

邮箱地址不会被公开。 必填项已用*标注