忘记了mysql登陆密码

来源:互联网 发布:数据采集终端工作原理 编辑:程序博客网 时间:2024/05/15 22:12

忘记了mysql 用户的登录密码,登录是报错

[mysql@localhost ~]$  mysql -u root -pEnter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

解决办法,设置一个参数不需要密码登录,

修改 mysql 的配置文件 /etc/my.cnf  ,增加skip-grant-tables 参数

[mysql@localhost ~]$ vi /etc/my.cnf # For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.7/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 = .....# socket = .....# 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 = 2Msql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES<span style="color:#ff0000;">skip-grant-tables</span>~


关闭数据库 :

[root@localhost ~]# /etc/init.d/mysql stop
Shutting down MySQL... SUCCESS! 


重新启动数据库

[root@localhost ~]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS! 



重新登录数据库,直接按回车:

[mysql@localhost ~]$ mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.9 MySQL Community Server (GPL)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 




0 0
原创粉丝点击