环境
- Ubuntu 18.04
- MySQL 5.7
MySQL 修改初始密码
通过sudo apt install mysql-server
安装完成之后,使用命令找到密码:
sudo cat /etc/mysql/debian.cnf
输出:
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = [需使用的密码]
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = [需使用的密码]
socket = /var/run/mysqld/mysqld.sock
使用 用户名debian-sys-maint
和 密码 登录, 更新root
用户的plugin
字段:
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
如果没有开启事务自动提交,则需跟上COMMIT;
MySQL 5.7
及以上版本修改root
密码:
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('new_password'