mysql -p密码 -u root -h localhost --default-character-set=utf8
-p和密码之间不需要空格
密码在data文件夹中的.err中
1 2 3 4 5 6 7
2019-07-09T06:01:57.352010Z 0 [System] [MY-013169] [Server] D:\Program Files\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server in progress as process 9640 2019-07-09T06:02:01.740043Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ot(=tBs2!a7W 2019-07-09T06:02:03.209213Z 0 [System] [MY-013170] [Server] D:\Program Files\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server has completed 2019-07-09T06:02:06.302561Z 0 [System] [MY-010116] [Server] D:\Program Files\mysql-8.0.16-winx64\bin\mysqld (mysqld 8.0.16) starting as process 8992 2019-07-09T06:02:08.875545Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2019-07-09T06:02:08.916009Z 0 [System] [MY-010931] [Server] D:\Program Files\mysql-8.0.16-winx64\bin\mysqld: ready for connections. Version: '8.0.16' socket: '' port: 3306 MySQL Community Server - GPL. 2019-07-09T06:02:09.169370Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
这里的随机密码是:ot(=tBs2!a7W
修改初始密码:
1
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 3.23.56 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> USE mysql; Database changed mysql> update user set authentication_string=''where user='root'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit