Ole Tange
Ole Tange

Reputation: 33748

Reset mysql root password on Ubuntu

Is there a simple way of setting the mysql root password on Ubuntu if I have root access and closing the database shortly is not an issue?

Upvotes: 1

Views: 4646

Answers (2)

Puujee.Ts
Puujee.Ts

Reputation: 91

Open your terminal

`sudo mysql -u root
use mysql;
SELECT user, plugin FROM user;
UPDATE user SET plugin = "mysql_native_password" WHERE user = "root" ;
exit
service mysql restart`

Upvotes: 0

Ole Tange
Ole Tange

Reputation: 33748

If you do not have many tables this should run in 10 seconds.

pass=MyNewPass
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '$pass';" > mysqlinit
sudo chown mysql:mysql mysqlinit
sudo /etc/init.d/mysql stop
sudo mysqld_safe --init-file=`pwd`/mysqlinit &
sleep 2
sudo killall mysqld
sudo /etc/init.d/mysql start
sudo rm mysqlinit
sql mysql://root:$pass@/mysql

Upvotes: 5

Related Questions