1

I recently installed mysql on my (cloud) server and then I ran sudo /usr/bin/mysql_secure_installation and disallowed remote root login. Then I created another user to run all my queries and gave it appropriate permissions. I can't remember the password now (or password got changed somehow) and am unable to connect to mysql. Whenever I try to connect using mysql -u user -p I get the following error

ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)

I tried following what answers to other question here on SO suggested but most of them require access to mysql shell.

I also tried to reconfigure using sudo dpkg-reconfigure mysql-server-5.5 (my version number is 5.5.41).

Using this I am able to set the root password but still can't connect it. I also tried running mysql in safe mode, as suggested by some user, with no luck.

Last thing I could think of was somehow renable the remote access for root, since I can reset it's password, and then reset the user password through mysql shell. So, I tried looking the /etc/mysql/my.cnf file but didn't see anything relevant.

Is there anything I am missing? How can I reset the password and get access again?

4

1 回答 1

2

停止 MySQL 服务

#/etc/init.d/mysql stop

使用 --skip-grant-tables 执行 MySQL 服务器

#mysqld -u mysql --skip-grant-tables &

以root身份执行mysql客户端

#mysql -u root

更新您的密码

mysql> update mysql.user set password=password('newpassword') where user='anotheruser';

重新加载权限

mysql> flush privileges;

杀死mysqld

#killall mysql

启动mysql守护进程

#/etc/init.d/mysql start
于 2015-03-28T01:27:33.257 回答