全新安装 MySQL 之后更改默认密码的步骤

Spoony 54.4m2020-09-28670 次点击
sudo cat /etc/mysql/debian.cnf

```
[client]
host = localhost
user = debian-sys-maint
password = xxx
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = xxx
socket = /var/run/mysqld/mysqld.sock
```

登录 mysql
```
mysql -u debian-sys-maint -pxxx
```

运行 sql 命令
```
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set authentication_string=PASSWORD("newpassword") where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1

mysql> update user set plugin="mysql_native_password";
Query OK, 1 row affected (0.00 sec)
Rows matched: 4 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye
```

运行命令
```
sudo /etc/init.d/mysql restart
```
收藏 ♥ 感谢
暂无回复

登录注册 后可回复。