mysql重置密码操作

avatar 2019年12月5日19:30:20 评论 1,034 次浏览

mysql长时间不用忘记了密码怎么办,重置一下来看看,下面是对于密码重置的操作,先看一下登录错误信息:

[root@localhost var]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost var]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

不管如何输入密码都是错的,进不了mysql的交互页面,下面修改一下mysql的配置文件。

[root@localhost var]# vi /etc/my.cnf 
innodb_lock_wait_timeout = 50
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

[mysqld]
#default-character-set=utf8
port            = 3306
socket          = /tmp/mysql.sock
datadir = /usr/local/mysql/var
log-error = /usr/local/mysql/var/error.log
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M

#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id       = 1
expire_logs_days = 10

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /usr/local/mysql/var
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/var
innodb_buffer_pool_size = 128M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

skip-grant-tables     #在mysqld中增加一行,修改后要注释掉,面的mysql被随意修改。

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

添加后,重启一下mysql,如果不能重启说明上次启动不成功,把进程kill掉即可,然后重启一下:

[root@localhost var]# /etc/init.d/mysql restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/var/localhost.localdomain.pid).

我这里就出现了重启错误,下面把进程kill掉在启动一下看看:

[root@localhost var]# ps -ef | grep mysql
root      9498 17343  0 17:23 pts/0    00:00:00 grep --color=auto mysql
root     16362     1  0 15:19 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/var --pid-file=/usr/local/mysql/var/localhost.localdomain.pid
mysql    16857 16362  0 15:19 ?        00:00:10 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --open-files-limit=65535 --pid-file=/usr/local/mysql/var/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
[root@localhost var]# kill -9 16857
[root@localhost var]# ps -ef | grep mysql
root      9500 17343  0 17:23 pts/0    00:00:00 grep --color=auto mysql
[root@localhost var]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS!

mysql启动正常,可以进入mysql修改密码了,我们可以直接给用户更新一下密码:

[root@localhost var]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.62-log Source distribution

Copyright (c) 2000, 2018, 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;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> use mysql;
Database changed
mysql> update user set password=password("root") where user="root";
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

这里需要注意,修改后一定要删除上面添加的配置,防止其他用户不用密码进入。

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: