2

In short,I have inherited a project... it has a live production site running on a LAMP stack. I have root access to the server nobody knows the mysql root password. In addition the user that the application uses cannot access the mysql client, for some reason the credentials only work from the application.

I am trying to reset the root password using the instructions from mysql https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

The server is running ubuntu 16 lts with mysql 5.7.19.

Following the above guide, they instruct mysql to be shutdown with the following:

kill `cat /mysql-data-directory/host_name.pid`

I run the sql script on startup... but the result is i still cannot login to the mysql shell via root :/

Anyone got a solid way to reset the root pass..?

Trying to get the service running with the skip grant tables and networking:

  1. Stop the service: /etc/init.d/mysql stop LOG OUTPUT
  2. Start the service with mysqld and options: mysqld --skip-grant-tables --skip-networking --user=root & the output
  3. Try to start the client but the client says:

    root@...:/home/john# mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

    1+ Exit 1 mysqld --skip-grant-tables --skip-networking --user=root

  4. When starting the mysql server this is the LOG OUTPUT


The answer below was correct, just ensure you have the /var/run/mysqld/ else mysqld cannot start.

  • the error.log might be found at /var/log/mysqld.log – Wilhelm Liao Feb 19 '18 at 13:19
  • Do you try to revise `my.cnf`? (1) stop mysqld server, (2) revise my.cnf and add `skip-grant-tables` and `skip-networking` under [mysqld] section (3) restart server in normal way, (4) login mysql using `mysql -u root` (now should without password) (5) execute reset password sql statement (6) stop mysqld server (7) rollback `my.cnf` (8) restart mysqld server in normal way – Wilhelm Liao Feb 19 '18 at 13:24
  • I found the output, added a link to the OP from the rel. step. –  Feb 19 '18 at 13:28
  • i found it, will post the answer in a minute, i just have to change the password and lock it back down –  Feb 19 '18 at 13:36
  • can you restart mysql server in normal way? `/etc/init.d/mysql start` or `service mysqld start`? – Wilhelm Liao Feb 19 '18 at 13:36
  • 1
    OK, this helped me answer the issue: https://stackoverflow.com/questions/34954455/mysql-daemon-lock-issue#answer-46779157 –  Feb 19 '18 at 13:39
  • 1
    So you were right.. it was there in the logs, but it tried to start then instantly shutdown, this outputted to the logs about 30 lines that are identical to a normal shutdown. Scroll up and you can see it could not write the lock file required in 2 lines in the log. This was due to `/var/run/mysqld/` not being present, it also didn't try to make it. mkdir /var/run/mysqld/ and chown it to mysql and it all worked based on your instructions. Thanks for your help! –  Feb 19 '18 at 13:42

1 Answers1

1

https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

B.5.3.2.3 Resetting the Root Password: Generic Instructions

  1. Stop the MySQL server if necessary, then restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.

-or-

https://www.codero.com/knowledge-base/content/33/296/en/how-to-reset-your-root-mysql-password.html

$  mysqld --skip-grant-tables --skip-networking &
$  mysql -u root

 ...change your password
 ...reset mysql without --skip-grant-tables and --skip-networking

UPDATE

It likely the mysqld cannot run as root or your system account. See here.

$ mysqld --skip-grant-tables --skip-networking --user=root &

or you can revise the my.cnf file directly after stop the mysql server. I recommend the way.

[mysqld]
...
# add the following two settings to configure variables for reseting password.
skip-grant-tables
skip-networking

After restart mysqld. Using the mysql cli client execute the following sql statement to change your password.

UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass')
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

Finally, stop mysqld, and rollback your my.cnf, then restart mysqld.

Wilhelm Liao
  • 829
  • 5
  • 12
  • Doesn't work.. ` /etc/init.d/mysql stop` then `mysqld --skip-grant-tables --skip-networking &` then try to `mysql -u root` but the error is it cannot connect: `ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)` –  Feb 17 '18 at 18:11
  • I am not sure. It likely the mysql cannot run as root or your system account. I updated the answer. – Wilhelm Liao Feb 17 '18 at 23:49
  • `mysqld --skip-grant-tables --skip-networking --user=root &` doesn't appear to start the service. So when i try to access the client it get connection error: ``` ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) [1]+ Exit 1 mysqld --skip-grant-tables --skip-networking --user=root ``` –  Feb 19 '18 at 09:19
  • @John, Could you show your error log? The `ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)` means the mysql server didn't start success. The message so less that I cannot know what happend in your mysql server. – Wilhelm Liao Feb 19 '18 at 10:28
  • Sure, i will add to the OP. And btw thanks for your time on this. –  Feb 19 '18 at 12:07
  • does not work - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) – Dimmduh Mar 05 '19 at 05:38
  • @Dimmduh try adding privilege to your mysql https://stackoverflow.com/questions/34954455/mysql-daemon-lock-issue#answer-46779157 – Wilhelm Liao Mar 10 '19 at 13:36