M
M
mr_blond972015-09-27 16:44:50
MySQL
mr_blond97, 2015-09-27 16:44:50

Need to reset mysql password in ubuntu, how to enter mysqld_safe mode?

Can't reset muscle password

$ sudo /etc/init.d/mysql stop

[ok]

$ sudo mysqld_safe --skip-grant-tables &

[1] 6302 $ 150927 15:21:29 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
150927 15:21:29 mysqld_safe Logging to '/var/log/mysql/error.log'.
150927 15:21:29 mysqld_safe A mysqld process already exists

Update:
Went in as root, did the same thing, it worked.
# sudo /etc/init.d/mysql stop
* Stopping MySQL database server mysqld                                                                              [ OK ]
# ps axu
# sudo mysqld_safe --skip-grant-tables &

Displays a message:
150927 16:24:06 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
150927 16:24:06 mysqld_safe Logging to '/var/log/mysql/error.log'.
150927 16:24:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

I wait 15 minutes, ^C, I look at the processes:
# ps axu
Suddenly there was no muscle in the processes. I rejoice, I continue:
# mysql -u root

mysql> use mysql;
mysql> update user set password=PASSWORD("mynewpassword") where User='root';
mysql> flush privileges;
mysql> \q

# sudo /etc/init.d/mysql stop
# sudo /etc/init.d/mysql start

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Ruslan Fedoseev, 2015-09-27
@mr_blond97

when you run mysqld_safe --skip_grant_tables the server is up and running. Reset the password in the next terminal.

V
Vlad Zhivotnev, 2015-09-27
@inkvizitor68sl

And once again I show the password reset script:

#!/bin/bash
mysql_password=$(pwgen -s 40 1)

/etc/init.d/mysql stop

echo "UPDATE mysql.user SET Password=PASSWORD('${mysql_password}') WHERE User='root';" > /tmp/mysql-set-pass
echo "FLUSH PRIVILEGES;" >> /tmp/mysql-set-pass

su -c "mysqld_safe --init-file=/tmp/mysql-set-pass &" mysql --shell=/bin/bash
sleep 5

echo "[mysql]
password = ${mysql_password}

[mysqldump]
password = ${mysql_password} " > /root/.my.cnf

/etc/init.d/mysql restart

mysql --password="" -e "SELECT 1;" 2>/dev/null && exit 1
mysql -e "SELECT 1;" 1>/dev/null || exit 1

rm /tmp/mysql-set-pass

N
Nazar Mokrinsky, 2015-09-27
@nazarpc

There is also a special command in Ubuntu to stop services:
Then check if it worked:
There, the initialization system may be different, perhaps it can catch the fall of the service and re-raise it on its own.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question