linux下mysql忘记密码解决方法
一、 检查mysql是否启动
运行命令:
ps -ef | grep -i mysql
如果开着就运行关闭的命令:
service mysqld stop
二、修改mysql的配置文件my.conf
执行命令:
vim /etc/my.cnf
再[mysqld]标签下添加一句:skip-grant-tables
[root@VM-0-8-centos etc]# vim /etc/my.cnf
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /www/server/data
default_storage_engine = InnoDB
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 100G
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 4K
read_buffer_size = 768K
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M
skip-grant-tables #跳过验证
#skip-name-resolve
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
slow_query_log=1
slow-query-log-file=/www/server/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
三、重启数据库
运行命令:
service mysqld start
四、进入到mysql数据库
运行命令:
mysql -u root
五、修改密码
执行命令:
use mysql;
update mysql.user set authentication_string=password('修改后的密码') where user='root';
六、删掉步骤二中的操作,重启服务器使用西密码登录
|