# 1. 切换路径到bin目录下(必须以管理员方式运行终端, 否则后面会因无权限导致失败) PS C:\Windows\system32> F: PS F:\> cd .\Program\ PS F:\Program> cd .\mysql-5.7.41-winx64\ PS F:\Program\mysql-5.7.41-winx64> cd bin # 2. 初始化, 获取默认密码 PS F:\Program\mysql-5.7.41-winx64\bin> .\mysqld --initialize --console # 此处应有一些内容(忘记复制了), 其中包含默认密码,在最后一行,注意查看!!! # 3. 安装mysql服务并启动 PS F:\Program\mysql-5.7.41-winx64\bin> .\mysqld --install mysql Service successfully installed. PS F:\Program\mysql-5.7.41-winx64\bin> net start mysql mysql 服务正在启动 . mysql 服务已经启动成功。 # 4. 连接MySQL PS F:\Program\mysql-5.7.41-winx64\bin> .\mysql -uroot -p Enter password: ************ # 输入刚刚获取的默认密码 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.41
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # 5. 修改密码为123456 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) # 6. 退出 mysql> exit Bye PS F:\Program\mysql-5.7.41-winx64\bin>