How to Change the Password on Ubuntu 22.04

February 25, 2020

Recovering the root password might seem frightening, but it doesn’t have to be difficult or complicated. On a RHEL/CentOS version 7 or later system, thanks to the Grub bootloader it’s actually pretty simple.

And that’s it. You should now have root password access to this system. 

Want to try out Red Hat Enterprise Linux? Download it now for free.

Guide

Method 1: Change Password via Command Line

How to Change the Password on Ubuntu 22.04

How to Change the Password on Ubuntu 22.04

You will be asked for the root password to be able to use root account.

How to Change the Password on Ubuntu 22.04
Given the second scenario, you hold sudo privileges. To change the password, run the previous command but with sudo this time.

How to Change the Password on Ubuntu 22.04

How to Change the Password on Ubuntu 22.04

Change Root User’s Password via Command Line

How to Change the Password on Ubuntu 22.04

Now, you can change the password for root using the passwd command as demonstrated below:

How to Change the Password on Ubuntu 22.04

You will be asked to enter the new password twice. Once the password is changed, you will see a confirmation message like this on your terminal:

How to Change the Password on Ubuntu 22.04

How to Change the Password on Ubuntu 22.04

Again, you will be asked to provide the new password twice.

How to Change the Password on Ubuntu 22.04

Method 2: Change User Password via GUI

To do that, go to the Settings.

How to Change the Password on Ubuntu 22.04

How to Change the Password on Ubuntu 22.04

To change the password first, enter the current password to authenticate yourself. Then provide the new password you want to keep. Make sure it matches a good security strength.

How to Change the Password on Ubuntu 22.04

Conclusion

In today’s guide, we saw in detail how to change a paAssword in Ubuntu. We first explored how to change a password via Ubuntu’s command line and then we saw how the same thing can be achieved via Ubuntu’s GUI.

About the author

Introduction

Temporary Switching to root

sudo command-name
sudo su -
whoami
Output

root

Changing Root Password

sudo passwd root

The new root password will be required to be entered and confirmed.

Make sure you use a strong and unique password when creating the password. The most critical part of your account’s security is having a strong password. A strong password often consists of at least 16 characters, one uppercase letter, one lowercase letter, one number, and one special character.

When you type the password, it does not appear on the screen.

Output

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

That’s it. The password for the root account has been updated.

You can now use the new password to log in to your Ubuntu system as root.

Conclusion

The root account in Ubuntu has no password by default. To run commands with root capabilities, the sudo command is advised.

You’ll need to set the root password before you can log in as root.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

First, you have to reboot into recovery mode.

If you have a single-boot (Ubuntu is the only operating system on your computer), to get the boot menu to show, you have to hold down the Shift key during bootup.
enter image description here
From the boot menu, select recovery mode, which is usually the second boot option.
enter image description here
After you select recovery mode and wait for all the boot-up processes to finish, you’ll be presented with a few options. In this case, you want the Drop to root shell prompt option so press the Down arrow to get to that option, and then press Enter to select it.

ls /home

To reset the password, type

passwd username
passwd susan

You’ll then be prompted for a new password. When you type the password you will get no visual response acknowledging your typing. Your password is still being accepted. Just type the password and hit Enter when you’re done. You’ll be prompted to retype the password. Do so and hit Enter again.

Now the password should be reset.

to return to the recovery menu.

After you get back to the recovery menu, select resume normal boot, and use Ubuntu as you normally would—only this time, you actually know the password!

Now just use:

SET PASSWORD FOR <user> = '<plaintext_password>'

Update 04/12 2021 AM 2:22:07 UTC/GMT -5 hours.

mysql> SET PASSWORD FOR'root'@'localhost' = PASSWORD('newpass');

or 1.The terminal enters the bin directory of MySQL

cd /usr/local/mysql/bin
mysql -u root -p

3.At this time you can use your default password

4.Perform operations in MySQL at this time

show databases;

So how to reset the root password? I checked a lot of information but it didn’t take effect.

1.It is still in the cd /usr/local/mysql/bin/ directory

After entering, you will be asked to enter your computer password.

When you enter it, nothing is displayed. After you enter it, press Enter

Then press enter

3.Cross the authorization verification

sh-3.2# ./mysqld_safe --skip-grant-tables &

If the execution of the command is stopped, and the execution has been completed at this time,

press Enter directly, and then exit to exit:

sh-3.2# exit

4.Re-enter MySQL at this time, no -p parameter, no password

./mysql -u root

5.Select the database MySQL (here MySQL refers to a database in MySQL,

there are other databases in MySQL, you can view it through show databases;)

use mysql;
update user set authentication_string=‘123456’ where User='root';

Note: The password field here is authentication_string,

not the password circulated on the Internet.

It is estimated that MySQL was updated later.

Re-enter MySQL and use the password you just set, is it all right?

Because you have just set to bypass the authorization authentication,

you can log in to MySQL directly without a password.

My stupid way is to restart the computer and log in to MySQL with the password again to see if the modification is effective;

I am trying to change root password in my Ubuntu system.

This is what I did:

ashot@ashot-desktop:~$ sudo passwd root 
passwd: Authentication token manipulation error 
passwd: password unchanged

How do I change root password in Ubuntu?

Eric Leschinski's user avatar

asked May 13, 2013 at 18:26

Ashot's user avatar

Usually there is no need to set a root password. See: https://help.ubuntu.com/community/RootSudo

To set or change your (root) password:

sudo -i
passwd

To lock it again

sudo passwd -dl root

answered May 13, 2013 at 20:24

Panther's user avatar

19 gold badges192 silver badges283 bronze badges

When you use sudo your already accessing root you don’t have to specify root.

sudo passwd

If your trying to do this from recovery root you should:

mount -rw -o remount / 
passwd

Дополнительно:  Root failed перевод на русский

heemayl's user avatar

20 gold badges198 silver badges264 bronze badges

answered Nov 15, 2013 at 5:34

Nade's user avatar

2 silver badges11 bronze badges

If ‘ashot’ is your root account, don’t call ‘sudo passwd’. I’ve been doing that for the past few months and it wouldn’t change my password.

To change my password, I had to call ‘passwd’ without ‘sudo’. Otherwise, the password modification is not taken account of.

answered Mar 23, 2015 at 22:01

Michael Fayad's user avatar

passwd: Authentication token manipulation error 
passwd: password unchanged

Try this steps;

— restart ubuntu, open it recovery mode
— drop root
— upgrade your ubuntu to a new version

This solved my problem, i hope it helps you too.

answered Aug 11, 2013 at 7:24

mehmet demir's user avatar

Possibly /etc/passwd and /etc/shadow don’t match.

Try to use command pwconv.

heemayl's user avatar

20 gold badges198 silver badges264 bronze badges

answered Nov 7, 2013 at 21:54

Pavel's user avatar

1 gold badge14 silver badges25 bronze badges

At first run this command:

sudo mysql
SELECT user,authentication_string,plugin,host FROM mysql.user;

now you can see something like this already :

+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             |                                           | auth_socket           | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Be sure to change password to a strong password of your choosing.
Then for reload your server to put your new changes into effect run this;

FLUSH PRIVILEGES;

So again check the authentication methods which has employed by your mysql , by this command:

SELECT user,authentication_string,plugin,host FROM mysql.user;

and now the output is :

+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             | *3636DACC8616D997782ADD0839F92C1571D6D78F | mysql_native_password | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+

as you can see in the grant table your root account has mysql_native_password
.
now you can exit MYSQL shell

exit;

That’s it.just you should restart mysql by sudo service mysql restart.
Now you can login to mysql as a root account with your password easily.

  1. Stop the MySQL server if it is running. For a server
    that is running as a Windows service, go to the Services
    manager: From the menu, select
    , then
    , then
    . Find the MySQL
    service in the list and stop it.

    If your server is not running as a service, you may need
    to use the Task Manager to force it to stop.

  2. Create a text file containing the password-assignment
    statement on a single line. Replace the password with
    the password that you want to use.

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  3. Save the file. This example assumes that you name the
    file C:\mysql-init.txt.

  4. Open a console window to get to the command prompt: From
    the menu, select
    , then enter
    as the command to be run.

  5. Start the MySQL server with the
    init_file system
    variable set to name the file (notice that the backslash
    in the option value is doubled):

    C:\> cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
    C:\> mysqld --init-file=C:\\mysql-init.txt

    If you installed MySQL to a different location, adjust
    the command accordingly.

    To have server output to appear in the console window
    rather than in a log file, add the
    --console option to the
    command.

    If you installed MySQL using the MySQL Installation
    Wizard, you may need to specify a
    --defaults-file option.
    For example:

    C:\> mysqld
             --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini"
             --init-file=C:\\mysql-init.txt

    The appropriate
    --defaults-file setting
    can be found using the Services Manager: From the
    menu, select
    , then
    , then
    . Find the MySQL
    service in the list, right-click it, and choose the
    Properties option. The Path
    to executable
    field contains the
    --defaults-file setting.

  6. After the server has started successfully, delete
    C:\mysql-init.txt.

You should now be able to connect to the MySQL server as
root using the new password. Stop the
MySQL server and restart it normally. If you run the server
as a service, start it from the Windows Services window. If
you start the server manually, use whatever command you
normally use.

However, to avoid security attacks, it is necessary to change the root password regularly. Because resetting the password time to time helps you to get rid of these issues, even if your ex-team member finds your old password, they wouldn’t be able to access the system.

We have two most common ways to change root password on Linux Mint 21 system:

1: Change root Password with sudo Permission

How to Change the Password on Ubuntu 22.04

In the next move, you will be asked to type the new root password for the Linux mint system:

How to Change the Password on Ubuntu 22.04

Re-enter the new root password you have set above for confirmation:

How to Change the Password on Ubuntu 22.04

Once both passwords match, you will get a message on terminal that you have successfully updated Linux Mint root password.

How to Change the Password on Ubuntu 22.04

2: Change root Password with root Permission

For this method, you should have changed the root password of the Linux Mint system at least one time before. And, you must know the current sudo password to gain root privileges. So, execute the mentioned command and type the current root password of your Linux system:

How to Change the Password on Ubuntu 22.04

In the next command, execute the ‘passwd’ command to the terminal for further process. This will allow you to modify the root password:

How to Change the Password on Ubuntu 22.04

Type the new password you want to set, and hit Enter:

How to Change the Password on Ubuntu 22.04

Re-enter the password you have set above. You will receive a successfully updated message if the password is entered correctly:

How to Change the Password on Ubuntu 22.04

3: Change root Password Using GUI

How to Change the Password on Ubuntu 22.04

Type the current root password and click to Authenticate button:

How to Change the Password on Ubuntu 22.04

How to Change the Password on Ubuntu 22.04

Once you clicked, a dialogue box of Change Password will be appeared on the screen:

How to Change the Password on Ubuntu 22.04

Type the new password of your choice in the New Password entry and re-write it on the Confirm Password tab. If your passwords match, then hit to Change button:

How to Change the Password on Ubuntu 22.04

The root password of the Linux Mint 21 system has changed successfully.

Conclusion

Through this guide, we have learned how to change the root password on Linux Mint 21 system. We have done it using two different approaches, one approach leads to CLI which includes sudo and root permissions. And in the second approach, we used the GUI method.

About the author

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.

Red Hat Training

A Red Hat training course is available for RHEL 8

23.1. Changing the root password as the root user

  • Root access
  • To change the root password, use:

    # passwd

    You are prompted to enter your current password before you can change it.

23.2. Changing or resetting the forgotten root password as a non-root user

  • You are able to log in as a non-root user.
  • You are a member of the administrative wheel group.
Дополнительно:  Прекращена работа программы root certificate installation mechanism for sputnik browser
  • $ sudo passwd root

    You are prompted to enter your current non-root password before you can change the root password.

23.3. Resetting the root password on boot

  1. Reboot the system and, on the GRUB 2 boot screen, press the key to interrupt the boot process.

    The kernel boot parameters appear.

    load_video
    set gfx_payload=keep
    insmod gzio
    linux ($root)/vmlinuz-4.18.0-80.e18.x86_64 root=/dev/mapper/rhel-root ro crash\
    kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet
    initrd ($root)/initramfs-4.18.0-80.e18.x86_64.img $tuned_initrd
  2. Go to the end of the line that starts with .

     ($root)/vmlinuz-4.18.0-80.e18.x86_64 root=/dev/mapper/rhel-root ro crash\
    kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet

    Press to jump to the end of the line.

  3. Add rd.break to the end of the line that starts with linux.

     ($root)/vmlinuz-4.18.0-80.e18.x86_64 root=/dev/mapper/rhel-root ro crash\
    kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet 
  4. Press to start the system with the changed parameters.

    The switch_root prompt appears.

  5. Remount the file system as writable:

    mount -o remount,rw /sysroot

    The file system is mounted as read-only in the /sysroot directory. Remounting the file system as writable allows you to change the password.

  6. Enter the chroot environment:

    chroot /sysroot

    The sh-4.4# prompt appears.

  7. Reset the root password:

    passwd
  8. Enable the SELinux relabeling process on the next system boot:

    touch /.autorelabel
  9. Exit the chroot environment:

    exit
  10. Exit the switch_root prompt:

    exit
  11. Wait until the SELinux relabeling process is finished. Note that relabeling a large disk might take a long time. The system reboots automatically when the process is complete.
  1. To verify that the root password is successfully changed, log in as a normal user and open the Terminal.
  2. Run the interactive shell as root:

    $ su
  3. Enter your new root password.
  4. whoami

    The output returns:

    root

But what do you do if the root password must be modified or reset?

This article shows you how to change the root password for your Linux Mint 20 system via three different methods.

Note: To change the root password, you must have either the current root password, sudo privileges, or have physical access to the system. It is also recommended to save the new password(s) in a secure location to be accessed when needed.

In this article, we will cover how to:

  1. Change or reset root password as root user
  2. Change or reset root password as sudo user
  3. Change or reset root password using GRUB menu

It is worth mentioning that all the commands included in this article have been tested in the Linux Mint 20 system. These commands have been performed in the Terminal, which can be opened using the Ctrl+Alt+T key shortcut, or by clicking on the terminal icon present in the taskbar of the Linux system.

You will be prompted to enter a new root password. Type the new password and hit the Enter key. Then, re-enter the password and press the Enter key to avoid any typos.

After entering the password, you will be shown a message saying that the password has been updated successfully.

How to Change the Password on Ubuntu 22.04

Change or Reset Root Password as Sudo User

After entering the password, you will be shown a message saying that the password has been updated successfully.

How to Change the Password on Ubuntu 22.04

Change or Reset Root Password Using GRUB Menu

Next, navigate to the Advanced options.

How to Change the Password on Ubuntu 22.04

Then, to switch to the edit window, click ‘e’ on the keyboard.

How to Change the Password on Ubuntu 22.04

How to Change the Password on Ubuntu 22.04

“linux bootvmlinuz-5.4.0—generic ==\2d26aa-051e
ro quiet splash”

How to Change the Password on Ubuntu 22.04

Replace ‘ro‘ with ‘rw’ in the above line and, at the end of the line, append ‘init=/bin/bash’. It should now look like this:

“linux bootvmlinuz-5.4.0—generic ==\
2d26aa-051e-4dbe-adb2-7fbb843f6581 rw quiet splash =bin”

Adding ‘rw’ and ‘init=/bin/bash’ in the above line basically tells the system to log in to bash with read/write privileges. Note that this configuration will only apply for the current boot, not for subsequent boots.

How to Change the Password on Ubuntu 22.04

How to Change the Password on Ubuntu 22.04

You will be prompted for the root password. Input the root password and press the Enter key. Then, retype the password and press Enter to avoid any typos.

After entering the password, you will then see a message stating that the new password has been updated.

How to Change the Password on Ubuntu 22.04

That is all you need to do to change or reset the root password of your Linux Mint 20 system without the sudo or root login. It is good practice to change the password frequently after some time, especially if you think it has been compromised.

Conclusion

In this article, we have identified three different methods to modify or reset the root password on your system. You can opt for any method, based on the privileges you have. If you have the root password or sudo privileges, you can easily reset the root password using the simple ‘passwd’ command. Otherwise, you can use the GRUB menu to change the root password, but only if you have physical access to the system.

I hope this article has helped you in changing or resetting the root password of your system.

About the author

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.

B.3.3.2 How to Reset the Root Password

If you have never assigned a root password
for MySQL, the server does not require a password at all for
connecting as root. However, this is
insecure. For instructions on assigning a password, see
Section 2.9.4, “Securing the Initial MySQL Account”.

B.3.3.2.1 Resetting the Root Password: Windows Systems
  1. Stop the MySQL server if it is running. For a server
    that is running as a Windows service, go to the Services
    manager: From the menu, select
    , then
    , then
    . Find the MySQL
    service in the list and stop it.

    If your server is not running as a service, you may need
    to use the Task Manager to force it to stop.

  2. Create a text file containing the password-assignment
    statement on a single line. Replace the password with
    the password that you want to use.

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  3. Save the file. This example assumes that you name the
    file C:\mysql-init.txt.

  4. Open a console window to get to the command prompt: From
    the menu, select
    , then enter
    as the command to be run.

  5. Start the MySQL server with the
    init_file system
    variable set to name the file (notice that the backslash
    in the option value is doubled):

    C:\> cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
    C:\> mysqld --init-file=C:\\mysql-init.txt

    If you installed MySQL to a different location, adjust
    the command accordingly.

    To have server output to appear in the console window
    rather than in a log file, add the
    --console option to the
    command.

    If you installed MySQL using the MySQL Installation
    Wizard, you may need to specify a
    --defaults-file option.
    For example:

    C:\> mysqld
             --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini"
             --init-file=C:\\mysql-init.txt

    The appropriate
    --defaults-file setting
    can be found using the Services Manager: From the
    menu, select
    , then
    , then
    . Find the MySQL
    service in the list, right-click it, and choose the
    Properties option. The Path
    to executable
    field contains the
    --defaults-file setting.

  6. After the server has started successfully, delete
    C:\mysql-init.txt.

You should now be able to connect to the MySQL server as
root using the new password. Stop the
MySQL server and restart it normally. If you run the server
as a service, start it from the Windows Services window. If
you start the server manually, use whatever command you
normally use.

Дополнительно:  Почему не работает батарея на ноутбуке? |

B.3.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems
  1. Stop the MySQL server if it is running. Locate the
    .pid file that contains the
    server’s process ID. The exact location and name of this
    file depend on your distribution, host name, and
    configuration. Common locations are
    /var/lib/mysql/,
    /var/run/mysqld/, and
    /usr/local/mysql/data/. Generally,
    the file name has an extension of
    .pid and begins with either
    mysqld or your system’s host name.

    $> kill `cat /mysql-data-directory/host_name.pid`

    Use backticks (not forward quotation marks) with the
    cat command. These cause the output
    of cat to be substituted into the
    kill command.

  2. Create a text file containing the password-assignment
    statement on a single line. Replace the password with
    the password that you want to use.

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  3. Start the MySQL server with the
    init_file system
    variable set to name the file:

    $> mysqld --init-file=/home/me/mysql-init &

    Other options may be necessary as well, depending on how
    you normally start your server. For example,
    --defaults-file may be
    needed before the
    init_file argument.

  4. After the server has started successfully, delete
    /home/me/mysql-init.

You should now be able to connect to the MySQL server as
root using the new password. Stop the
server and restart it normally.

B.3.3.2.3 Resetting the Root Password: Generic Instructions

The preceding sections provide password-resetting
instructions specifically for Windows and Unix and Unix-like
systems. Alternatively, on any platform, you can reset the
password using the client (but this
approach is less secure):

  1. Connect to the MySQL server using the
    client; no password is
    necessary because the server was started with
    --skip-grant-tables:

    $> mysql
  2. In the mysql client, tell the server
    to reload the grant tables so that account-management
    statements work:

    mysql> FLUSH PRIVILEGES;
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

You should now be able to connect to the MySQL server as
root using the new password. Stop the
server and restart it normally (without the
--skip-grant-tables option
and without enabling the
skip_networking system
variable).

B.3.3.2 How to Reset the Root Password

If you have never assigned a root password
for MySQL, the server does not require a password at all for
connecting as root. However, this is
insecure. For instructions on assigning a password, see
Section 2.9.4, “Securing the Initial MySQL Account”.

B.3.3.2.1 Resetting the Root Password: Windows Systems
  1. Stop the MySQL server if it is running. For a server
    that is running as a Windows service, go to the Services
    manager: From the menu, select
    , then
    , then
    . Find the MySQL
    service in the list and stop it.

    If your server is not running as a service, you may need
    to use the Task Manager to force it to stop.

  2. Create a text file containing the password-assignment
    statement on a single line. Replace the password with
    the password that you want to use.

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  3. Save the file. This example assumes that you name the
    file C:\mysql-init.txt.

  4. Open a console window to get to the command prompt: From
    the menu, select
    , then enter
    as the command to be run.

  5. Start the MySQL server with the
    init_file system
    variable set to name the file (notice that the backslash
    in the option value is doubled):

    C:\> cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"
    C:\> mysqld --init-file=C:\\mysql-init.txt

    If you installed MySQL to a different location, adjust
    the command accordingly.

    To have server output to appear in the console window
    rather than in a log file, add the
    --console option to the
    command.

    If you installed MySQL using the MySQL Installation
    Wizard, you may need to specify a
    --defaults-file option.
    For example:

    C:\> mysqld
             --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 5.7\\my.ini"
             --init-file=C:\\mysql-init.txt

    The appropriate
    --defaults-file setting
    can be found using the Services Manager: From the
    menu, select
    , then
    , then
    . Find the MySQL
    service in the list, right-click it, and choose the
    Properties option. The Path
    to executable
    field contains the
    --defaults-file setting.

  6. After the server has started successfully, delete
    C:\mysql-init.txt.

You should now be able to connect to the MySQL server as
root using the new password. Stop the
MySQL server and restart it normally. If you run the server
as a service, start it from the Windows Services window. If
you start the server manually, use whatever command you
normally use.

UPDATE mysql.user
    SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
    WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

B.3.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems
  1. Stop the MySQL server if it is running. Locate the
    .pid file that contains the
    server’s process ID. The exact location and name of this
    file depend on your distribution, host name, and
    configuration. Common locations are
    /var/lib/mysql/,
    /var/run/mysqld/, and
    /usr/local/mysql/data/. Generally,
    the file name has an extension of
    .pid and begins with either
    mysqld or your system’s host name.

    $> kill `cat /mysql-data-directory/host_name.pid`

    Use backticks (not forward quotation marks) with the
    cat command. These cause the output
    of cat to be substituted into the
    kill command.

  2. Create a text file containing the password-assignment
    statement on a single line. Replace the password with
    the password that you want to use.

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  3. Start the MySQL server with the
    init_file system
    variable set to name the file:

    $> mysqld --init-file=/home/me/mysql-init &

    Other options may be necessary as well, depending on how
    you normally start your server. For example,
    --defaults-file may be
    needed before the
    init_file argument.

  4. After the server has started successfully, delete
    /home/me/mysql-init.

You should now be able to connect to the MySQL server as
root using the new password. Stop the
server and restart it normally.

UPDATE mysql.user
    SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
    WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

B.3.3.2.3 Resetting the Root Password: Generic Instructions

The preceding sections provide password-resetting
instructions specifically for Windows and Unix and Unix-like
systems. Alternatively, on any platform, you can reset the
password using the client (but this
approach is less secure):

  1. Connect to the MySQL server using the
    client; no password is
    necessary because the server was started with
    --skip-grant-tables:

    $> mysql
  2. In the mysql client, tell the server
    to reload the grant tables so that account-management
    statements work:

    mysql> FLUSH PRIVILEGES;
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

You should now be able to connect to the MySQL server as
root using the new password. Stop the
server and restart it normally (without the
--skip-grant-tables option
and without enabling the
skip_networking system
variable).

UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass')
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

Оцените статью
Master Hi-technology
Добавить комментарий