After the window system installed mysql to get the default password

No password, the default password acquisition method

The first step: go in mysql root directory, if there is no data can create a new folder, you can not find my.ini file also create a my.ini (created in the root directory will overwrite the source file Parameter reconfigured so can not find the source file does not matter, linux system configuration file my.cnf)

My.ini with the following parameter values:

[mysqld] 
#mysql所在目录
basedir=C:\Program Files\MySQL\MySQL Server 5.7    

#mysql所在目录\data,为数据存储地址
datadir=C:\Program Files\MySQL\MySQL Server 5.7\data    

#开启时间戳打印
explicit_defaults_for_timestamp=true               

The second step: open an administrator cmd, cd to the directory mysql \ under the bin, enter: mysqld --install

This command is executed after installation services, prompt successful English (remove service command: mysqld --remove)

The third step: performing mysqld --initialize --user = mysql --console

You can also perform mysqld --initialize the --console , perform this step, because there is no data folder in MySQL5.7, the need to generate data folder with these orders, and initialize the random access code, executing the will of a large English, find this sentence a temporary password is generated for root @ localhost: the default password on it

.Err found at the end of the data file is opened, the information printed inside there, but also kept the default password just to print

Step four: Perform mysql -u root -p default password, the new password to change into mysql

Enter the password change command

use mysql; 
update user set password=password('新密码') where user='root' and host='localhost'; 
flush privileges; 

After the re-landing mysql, enter the new password.

Expand knowledge: three ways to change your password

方法1: 用SET PASSWORD命令
首先登录MySQL。
格式:mysql> set password for 用户名@localhost = password('新密码');
例子:mysql> set password for root@localhost = password('123');

方法2:用mysqladmin
格式:mysqladmin -u用户名 -p旧密码 password 新密码
例子:mysqladmin -uroot -p123456 password 123

方法3:用UPDATE直接编辑user表 (忘记密码,推荐使用)
首先登录MySQL。
mysql> use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
mysql> flush privileges;

Guess you like

Origin www.cnblogs.com/cool-fun/p/12377112.html