Windows下Mysql5.7忘记root密码或没有my.ini解决

Windows下Mysql5.7忘记root密码的解决方法

 

1、打开第一个cmd窗口执行 net stop mysql57

2、在第一个cmd窗口执行 mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.7\my.ini" --skip-grant-tables   ---注意路径(以你的实际情况为准)

如果没有my-default.ini,my.ini,那就复制一个/或者创建一个,

my-default.ini

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

 my.ini

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
performance_schema_max_table_instances=400
table_definition_cache=400
table_open_cache=256
character_set_server=utf8
lower_case_table_names=1

3、打开第二个cmd窗口执行 mysql -uroot -p        提示输入密码,直接回车(不用输入密码)

4、选择数据库:use mysql;

5、更新root的密码:update user set authentication_string=password('新密码') where user='root' and Host='localhost';

6、刷新权限:flush privileges;

7、退出:quit

8、重新登录:mysql -uroot -p       提示输入密码,这时输入密码才能登录。完成!!!

 

 

启动服务提示“本地计算机上的mysql服务启动后停止,某些服务在未由其他服务或程序使用时将自动停止。

解决

 

备份data中的数据,然后删除掉data中所有的东西(如果删除不掉请在进程中找到mysqld.exe并且关闭)

 

打开CMD

 

cd E:\AppServ\MySQL\bin

 

mysqld --initialize

 

等待重新初始化完毕,再还远自己备份的data中的数据,然后启动mysql服务

你可能感兴趣的:(技术记录)