Answer the question
In order to leave comments, you need to log in
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
# sudo /etc/init.d/mysql stop
* Stopping MySQL database server mysqld [ OK ]
# ps axu
# sudo mysqld_safe --skip-grant-tables &
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
# ps axu
# 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
when you run mysqld_safe --skip_grant_tables the server is up and running. Reset the password in the next terminal.
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
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 questionAsk a Question
731 491 924 answers to any question