P
P
Petr Volkhanov2015-06-02 23:33:20
MySQL
Petr Volkhanov, 2015-06-02 23:33:20

How to find the root user password for a MySQL database in Ubuntu?

I got one VPS server, as an inheritance, so to speak. The former owner has not been contacted. How do I find out the root user password for a MySQL database? Where is it stored on the Ubuntu 14.04 filesystem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
m0rd, 2015-06-02
@m0rd

The password is stored in the database. Drop it and that's it.

V
Vlad Zhivotnev, 2015-06-03
@inkvizitor68sl

#!/bin/bash

mysql_password="новый_пароль"

/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

Reset the script to a new password.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question