Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

MySQL Recover / Change root Password

By editor , 27 June, 2016
Question

How to recover and/or change the MySQL root password on linux ?

1. Stop the MySQL service of started

sudo /etc/init.d/mysql stop #On Debian based linux systems (Ubuntu, Mint ...)
sudo /etc/init.d/mysqld stop #On Red Hat Enterprise based Linux systems (CentOS, Fedora, Suse ...)

2. Start MySQL without a password

sudo mysqld_safe --skip-grant-tables & # Add '&' to start process on new thread

3. Connect to MySQL

mysql -uroot

4. Set a new MySQL root password

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

5. Stop and start the MySQL service

#On Debian based linux systems (Ubuntu, Mint ...)
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

#On Red Hat Enterprise based Linux systems (CentOS, Fedora, Suse ...)
sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysqld start


Now you can login to the database using new password

mysql -u root -p

 

Change MySQL Root password using mysqladmin

Example:
mysqladmin -u root -p'root' password 'newpassword'

 

Change password use mysql cli
mysql mysql -u root -p
UPDATE user SET password=PASSWORD('YourNewRootPassword') WHERE user="root";
flush privileges;
quit

Tags

  • Server
  • Shell
  • Database
Mysql Tips. Useful commands

Comments

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer