今天安装mysql5.7.1.20需要使用管理员身份运行cmd去执行命令,在此为自己备份3点,(本人现在是win10)
1、win+X可以进入选择打开的选择界面,选择windows powerShell(管理员)运行即可;
2、mysqld开头的命令需要在mysqld前面加上.\,
ps: .\mysqld --initialize-insecure --user=mysql
3、mysqld --initialize-insecure --user=自定义用户名,这是初始化用于生成mysql-5.7.20-winx64里面的data文件的,如果通过此方式生成data文件,启动mysql服务会失败。
补充:
如果mysqld --initialize --user=mysql --console初始化会生成一个随机码,这个一定要记得,后面修改密码需要这个临时密码的。
set password = password('root')我这个版本修改密码是执行这个语句的,不过修改前需要进入到bin里面,再执行
mysql -u root -p命令,然后输入随机码,最后重启一个管理员运行的cmd窗口,进入bin里面输入
mysql回车
就可以去修改密码了。
ps:
PS D:\MySQL\mysql-5.7.20-winx64\bin> .\mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.20
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
mysql>set password = password('root')
Query OK, 0 rows affected, 1 warning (0.00 sec)