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服務

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章