本文记录一下我在mac环境下安装mysql-5.7.16遇到的坑。我用的是二进制文件tar.gz压缩包的形式安装。
1号坑
安装完成后,使用安装过程随机生成的密码登录,执行命令都是失败的,都会给出如下提示
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
查阅资料后才知道,原来是Password Expiration Policy搞的鬼,自从5.7.4版本后就有了这么一个东西(详情参考最后的参考网站)。执行下面的代码可解。
mysql> SELECT 1;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> ALTER USER USER() IDENTIFIED BY 'new_password';
Query OK, 0 rows affected (0.01 sec)
mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
启动
记得启动mysql是mysqld的命令,但是不能用root使用mysqld,否则打印如下错误
2016-11-17T13:54:04.161157Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
所以启动相关的命令如下
cd /usr/local/mysql
# 启动
support-files/mysql.server start
# 重启
support-files/mysql.server restart
# 停止
support-files/mysql.server stop
# 检查 MySQL 运行状态
support-files/mysql.server status
允许mysql远程访问
- 更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称’%’。
或者新加条记录,“host” 项为要访问的ip地址,并授权。重启mysql服务。 - 授权
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
参考网站
http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
https://dev.mysql.com/doc/refman/5.7/en/password-expiration-policy.html
http://blog.csdn.net/cin_ie/article/details/50364756