简略步骤
    任务一 更改root密码 - 图1

    1. 更改环境变量
      修改/etc/profile文件,文件尾添加mysql的绝对路径,修改环境变量

      1. //修改配置文件
      2. # vim /etc/proflie
      3. //在文件的最下面添加mysql的绝对路径
      4. export PATH=$PATH:/usr/local/mysql/bin/
    2. 创建MySQL密码
      使用命令mysqladmin -uroot password ‘bai’为root用户创建初始密码 ```powershell [root@bai mysql]# mysqladmin -uroot password ‘bai’ Warning: Using a password on the command line interface can be insecure. //注释:可以忽略warning内容,指的是明码输入屏幕不安全。 //使用命令mysql -uroot -pbai,就可以完成初始密码登录 [root@bai mysql]# mysql -uroot -pbai Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.6.47 MySQL Community Server (GPL)

    Copyright (c) 2000, 2020, 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>

    1. 3. 密码重置<br />修改配置文件/etc/my.cnf,在mysqld配置段,增加字段skip-grant
    2. ```powershell
    3. //修改MySQL配置文件
    4. [root@bai mysql]# vim /etc/my.cnf
    5. //在[mysqld]下面加
    6. skip-grant
    7. //修改完成后,重启MySQL服务
    8. [root@bai mysql]# /etc/init.d/mysqld restart
    9. Shutting down MySQL.. SUCCESS!
    10. Starting MySQL. SUCCESS!
    11. 使用命令登入MySQL(修改的配置段,是完成忽略授权的操作,可以直接登入,无需输入用户名密码),切换到MySQL库,对user表进行更新操作.
    12. //登录无需密码
    13. [root@bai mysql]# mysql -uroot
    14. //切换库
    15. mysql> use mysql;
    16. Reading table information for completion of table and column names
    17. You can turn off this feature to get a quicker startup with -A
    18. //切换完成
    19. Database changed
    20. //修改密码
    21. mysql> update user set password=password('bai123') where user='root';
    22. Query OK, 4 rows affected (0.00 sec)
    23. Rows matched: 4 Changed: 4 Warnings: 0
    24. mysql> quit
    25. Bye
    26. 主要://修改完成后,确认新密码登录有效。把/etc/my.cnf改回原有状态,并重启MySQL服务。
    27. [root@bai mysql]# vim /etc/my.cnf
    28. [root@bai mysql]#
    29. [root@bai mysql]#
    30. [root@bai mysql]#
    31. [root@bai mysql]# /etc/init.d/mysqld restart
    32. Shutting down MySQL.. SUCCESS!
    33. Starting MySQL. SUCCESS!
    34. [root@bai mysql]# mysql -uroot -p'bai123'
    35. Warning: Using a password on the command line interface can be insecure.
    36. Welcome to the MySQL monitor. Commands end with ; or \g.
    37. Your MySQL connection id is 3
    38. Server version: 5.6.47 MySQL Community Server (GPL)
    39. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    40. Oracle is a registered trademark of Oracle Corporation and/or its
    41. affiliates. Other names may be trademarks of their respective
    42. owners.
    43. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    44. mysql>
    45. //完成