ubuntu安装mysql添加密码

ubuntu安装mysql5.7后没有密码,添加密码。

这里是关键点,由于mysql5.7没有password字段,密码存储在authentication_string字段中,password()方法还能用

在mysql中执行下面语句修改密码

show databases;
 
use mysql;
  
update user set authentication_string=PASSWORD("自定义密码") where user='root';
  
update user set plugin="mysql_native_password";
  
flush privileges;
  
quit;

Ubuntu 重置MySQL Root密1.停止MySQL服务

$ service mysql stop

 

2.跳过认证启动MySQL服务

$ mysqld_safe --skip-grant-tables

3.免密码登录MySQL

$ mysql -u root

 mysql> use mysql;

MySQL 5.7 以前版本

mysql> update user set Password=PASSWORD('new_password') where user='root';

MySQL 5.7 以后版本(Password字段改为了authentication_string)

mysql> update user set authentication_string=PASSWORD('new_password') where user='root';

mysql> flush privileges;

mysql> exit;

4.开启MySQL服务

$ service mysql start

5.使用刚刚重置的新密码登录

$ mysql -u root -p 

原文地址:https://www.cnblogs.com/shenZS/p/13541707.html