简略步骤
更改环境变量
修改/etc/profile文件,文件尾添加mysql的绝对路径,修改环境变量//修改配置文件# vim /etc/proflie//在文件的最下面添加mysql的绝对路径export PATH=$PATH:/usr/local/mysql/bin/
创建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>
3. 密码重置<br />修改配置文件/etc/my.cnf,在mysqld配置段,增加字段skip-grant。```powershell//修改MySQL配置文件[root@bai mysql]# vim /etc/my.cnf//在[mysqld]下面加skip-grant//修改完成后,重启MySQL服务[root@bai mysql]# /etc/init.d/mysqld restartShutting down MySQL.. SUCCESS!Starting MySQL. SUCCESS!使用命令登入MySQL(修改的配置段,是完成忽略授权的操作,可以直接登入,无需输入用户名密码),切换到MySQL库,对user表进行更新操作.//登录无需密码[root@bai mysql]# mysql -uroot//切换库mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A//切换完成Database changed//修改密码mysql> update user set password=password('bai123') where user='root';Query OK, 4 rows affected (0.00 sec)Rows matched: 4 Changed: 4 Warnings: 0mysql> quitBye主要://修改完成后,确认新密码登录有效。把/etc/my.cnf改回原有状态,并重启MySQL服务。[root@bai mysql]# vim /etc/my.cnf[root@bai mysql]#[root@bai mysql]#[root@bai mysql]#[root@bai mysql]# /etc/init.d/mysqld restartShutting down MySQL.. SUCCESS!Starting MySQL. SUCCESS![root@bai mysql]# mysql -uroot -p'bai123'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 3Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>//完成
