Ubuntu安装5.7mysql坑,需要注意的问题

  • Post author:
  • Post category:mysql


最近在ubuntu平台安装最新版本mysql5.7,遇到坑:

  • Mysql出现任何用户不用密码|使用任何密码都能登录的问题 【主要是因为没有删除匿名用户】
  • 修改用户密码,提示没有password字段


对于第一个坑


直接导致结果是:项目上线后,发现连续几天有人半夜攻击服务器数据库,导致mysql数据库再也连接不上,整个产品线数据请求接口瘫痪。


对于第二个坑


无法实现更改用户密码,以前版本一直都是这样的呀。

解决方案:

坑1:

  1. 删除user表中用户名为“”的数据(我使用navicat删除的话没有效果,应该是没有刷新权限导致的,执行flush

    privileges):
  2. use mysql;
  3. delete from user where user = “”;
  4. flush privileges;

再试一下,完美解决.

坑2:

update user set password=password(“新密码”) where user=”用户名”;

执行后报错  ERROR 1054(42S22) Unknown column ‘password’ in ‘field list’

错误的原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string

所以请使用一下命令:

>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.18-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Database changed
mysql> select User from user;  #此处为查询用户命令
+-----------+
| User      |
+-----------+
| *******  |
| mysql.sys |
| root      |
+-----------+
rows in set (0.00 sec)

mysql> update user set password=password("*******") where user="*******";  #修改密码报错
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update mysql.user set authentication_string=password('*******') where user='*******';  #修改密码成功
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;  #立即生效
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

n>mysql -u ******* -p #以该用户登录成功.
Enter password: ********
…………………………
mysql>

最重要的执行命令:

example:
update mysql.user set authentication_string=password('wanxiang2016') where user='root';






允许远程访问

  1. 更改配置

    注释bind-address = 127.0.0.1。
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

将bind-address = 127.0.0.1注释掉(即在行首加#),如下:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address          = 127.0.0.1
  1. 增加允许远程访问的用户或者允许现有用户的远程访问

    给root授予在任意主机(%)访问任意数据库的所有权限。SQL语句如下:
mysql> grant all privileges on *.* to 'root'@'%' identified by '你的密码' with grant option;



版权声明:本文为ItJavawfc原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。