MySQL5.7初始密码问题

  今天在实验室的电脑上安装MySQL5.7的时候,下载了ZIP版,在配置好环境变量之后遇到了不知道初始密码的问题,查找了很多帖子都不行,最后这样解决了问题:

  1.在MySQL的安装目录下(例如:D:\develop\mysql-5.7.19-winx64)手动新建一个文件,命名为my.ini,再新建一个文件夹data,my.ini文件中,复制内容如下:

  

复制代码
[mysql]  
# 设置mysql客户端默认字符集  
default-character-set=utf8   
[mysqld]  
#设置3306端口  
port = 3306   
# 设置mysql的安装目录  
basedir=D:\develop\mysql-5.7.19-winx64  
# 设置mysql数据库的数据的存放目录  
datadir=D:\develop\mysql-5.7.19-winx64\data  
# 允许最大连接数  
max_connections=200  
# 服务端使用的字符集默认为8比特编码的latin1字符集  
character-set-server=utf8  
# 创建新表时将使用的默认存储引擎  
default-storage-engine=INNODB 
复制代码

2.进入mysql的安装目录下,打开命令提示符(可以Shift+右键->选择命令提示符)输入:mysqld --skip-grant-tables

  回车之后就不要动了,再新打开一个命令提示符窗口,同样进入mysql的安装目录下,

  输入:mysql -u root -p

  密码为空,直接回车

  接着输入以下命令:

  use mysql;

  update user set authentication_string=password("123456") where user="root";

  flush privileges;

  以上三条命令执行完毕之后,打开命令提示符窗口,

  输入mysql -u root -p,回车(前提是配置好了环境变量,没有配置的可以自行百度)

  输入密码:123456

  成功!

============================================================

安装了mysql5.7之后初始密码不再默认为空

1.查看初始密码:

[root@VM_225_102_centos ~]# grep 'temporary password' /var/log/mysqld.log 
2016-07-08T02:25:46.311098Z 1 [Note] A temporary password is generated for root@localhost: MtPqF0/oN5zo

即初始密码为 MtPqF0/oN5zo    (密码是随机产生的,每台机器产生的都不一样哦)

或者

另外一种方法查看默认密码:

[root@localhost src]# cat /root/.mysql_secret

# The random password set for the root userat Fri Jan 10 20:00:34 2014 (local time): aJqZsA2m

这里的aJqZsA2m就是生成的root随机密码啦

2.登录及修改密码:

[root@VM_225_102_centos ~]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.11


Copyright (c) 2000, 2016, 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.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


登录之后 第一步必须先修改密码,否则其他操作都执行不了。


修改密码的方法:


mysql> alter user root@localhost identified by 'tyzZ001!';
Query OK, 0 rows affected (0.00 sec)

新修改的密码中 必须包含 大小写字母数字及符号

发现有些不支持上述方法 另提供一种思路 

点击查看:MySQL忘记root密码解决方案

猜你喜欢

转载自blog.csdn.net/demonson/article/details/80852673