一、命令安装mysql

apt install mysql-server

二、修改账号和密码

  • 默认的root没有密码
    ```shell vim /etc/mysql/debian.cnf # 查看用户信息
  1. 使用root进入后修改host信息
  2. ```sql
  3. use mysql;
  4. select User,Host from user; # 查看配置
  5. update user set Host ='%' where User = 'root'; # 修改localhost为%,能够让外面连接进来
  6. update user set authentication_string=password('qq1448265203') where user='root'; # 修改root用户的密码
  7. grant all privileges on *.* to 'root'@'%' identified WITH mysql_native_password BY by 'qq1448265203';
  8. MYSQL:
  9. //把系统的root修改密码
  10. update mysql.user set authentication_string=password('qq1448265203') where user='root';
  11. //能远程访问
  12. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'qq1448265203';
  13. update user set authentication_string=PASSWORD('qq1448265203') where user='root'; # 更改密码
  14. grant all privileges on *.* to 'root'@'%' identified WITH mysql_native_password BY by 'qq1448265203';
  15. ALTER USER 'root’@‘localhost' IDENTIFIED WITH mysql_native_password BY ‘你的密码’;

参考博客