sudo cat /etc/mysql/debian.cnf # Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = TSrgdwiw4RHkTLKP socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = debian-sys-maint password = TSrgdwiw4RHkTLKP socket = /var/run/mysqld/mysqld.sock
使用上面的自动生成的账号密码登录,然后修改root密码
1 2 3 4 5
>use mysql; >update user set authentication_string=password('123456') where user='root' and host ='localhost'; >update user set plugin="mysql_native_password"; >flush privileges; >quit;
#注意:mysql8更新了密码规范,要求必须包含大小写,数字,特殊字符。 #上述更新root密码过程在更新root密码时会出错 #通过临时账号密码登录之后,使用下述方法更改root密码。参考https://zhuanlan.zhihu.com/p/259617090 use mysql alter user 'root'@'localhost' identified with mysql_native_password by 'Abcdef_1234'; Query OK, 0 rows affected (0.16 sec)
CREATE TABLE IF NOT EXISTS `secret`( `id` INT UNSIGNED AUTO_INCREMENT, `item` VARCHAR(20) NOT NULL, `account` VARCHAR(100) NOT NULL, `password` VARCHAR(100) NOT NULL, `email` VARCHAR(100) NOT NULL, PRIMARY KEY ( `id` ) )ENGINE=InnoDB DEFAULT CHARSET=utf8;