00:mysql版本及相关实例的配置文件所在路径
[root@temp ~]# mysql -V #mysql版本
mysql Ver 14.14 Distrib 5.7.22, for linux-glibc2.12 (x86_64) using EditLine wrapper
[root@temp ~]# tree -L 1 /mysql/data/3306/ #mysql实例相关文件的存放位置
/mysql/data/3306/
├── data
├── exit
├── my.cnf
├── mysqld
├── mysql.pid
├── mysql.sock
└── mysql.sock.lock
1 directory, 6 files
01:我在最开始部署mysql的时候就为自己创建了一个超级用户(用户:chenliang@% 密码:chenliang 权限:all 针对库:*.* 其它:拥有为其它用户分配权限的权限)
mysql> grant all on *.* to 'chenliang'@'%' identified by 'chenliang' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show grants for 'chenliang'@'%';
+------------------------------------------------------------------+
| Grants for chenliang@% |
+------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'chenliang'@'%' WITH GRANT OPTION |
+------------------------------------------------------------------+
1 row in set (0.00 sec
02:现有mysql实例默认的超级用户root@localhost的密码为chenliang,我现在将其修密码修改成123456
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
03:现有我用root@localhost用户登录,使用原来的密码chenliang,我不知道已修改了密码(模拟哈)
[root@temp 3306]# mysql -uroot -pchenliang -S mysql.sock #命令行不能暴露密码哈,这里是模拟
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
04:我现有用chenliang@%用户登录,密码为chenliang
[root@temp 3306]# mysql -uchenliang -h127.0.0.1 -pchenliang -P3306 #命令行不能暴露密码哈,这里是模拟
mysql>
mysql> alter user 'root'@'localhost' identified by 'chenliang'; #现在我将root@localhost用户的密码修改成了chenliang哈
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,authentication_string,password_expired from mysql.user where user='root' and host="localhost";
+------+-----------+-------------------------------------------+------------------+
| user | host | authentication_string | password_expired |
+------+-----------+-------------------------------------------+------------------+
| root | localhost | *D072DB593E2E7B068E887A452EB1DB3981A5D844 | N |
+------+-----------+-------------------------------------------+------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
05:用root@localhost用户登录,密码chenliang,验证是否修改成功
[root@temp 3306]# mysql -uroot -pchenliang -S mysql.sock -e "show databases;" #命令行不能暴露密码哈,这里是模拟
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+