Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
edited by
How can I able to change the MySQL root password and username in ubuntu server? Is it must to stop the MySQL service before setting up any of the changes?

I do have the phpmyadmin setup as well, does phpmyadmin get updated automatically?

1 Answer

0 votes
by (12.7k points)
edited by
  1. Stop the MySQL Server: sudo /etc/init.d/mysql stop
  2. Start the mysqld configuration: sudo mysqld --skip-grant-tables &

    In some circumstances, you need to be creating the /var/run/mysqld first:

    sudo mkdir -v /var/run/mysqld && sudo chown mysql /var/run/mysqld
    
  3. Run: sudo service mysql start
  4. Then log in to the MySQL as root: mysql -u root mysql
  5. Replace YOURNEWPASSWORD with your new password:

    UPDATE
      mysql.user
    SET
      Password = PASSWORD('YOURNEWPASSWORD')
    WHERE
      User = 'root';
    FLUSH PRIVILEGES;
    exit;
    

Note: on some versions, if password column doesn't exist, you may want to try:

UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';

Interested in SQL ? Check out this SQL Certification by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...