xxxxxxxxxx
-- Assuming the user wants to change the password of a user named 'username' to 'newpassword'
-- Connect to MySQL server
mysql -u root -p
-- Change the password for the user 'username'
ALTER USER 'username'@'localhost' IDENTIFIED BY 'newpassword';
FLUSH PRIVILEGES;
xxxxxxxxxx
ALTER USER 'user-name'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';FLUSH PRIVILEGES;
xxxxxxxxxx
SET PASSWORD FOR 'user-name'@'localhost' = PASSWORD('NEW_USER_PASSWORD');FLUSH PRIVILEGES;
xxxxxxxxxx
ALTER USER 'user-name'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';
FLUSH PRIVILEGES
xxxxxxxxxx
ALTER USER 'user-name'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';
FLUSH PRIVILEGES;
xxxxxxxxxx
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
xxxxxxxxxx
# `SET PASSWORD FOR <user> = PASSWORD('<plaintext_password>')` is deprecated
SET PASSWORD FOR <user> = '<plaintext_password>';
FLUSH PRIVILEGES;
How To Change/Update MySQL Password
xxxxxxxxxx
PASSWORD_TEXT The plain text of the password
PASSWD_HASH the password hash string copied from another user
USER The MySQL User Account
HOST The Users Hostname, domain/IP (% is wildcard eg '%' or '192.168.%')
How To Update MySQL Password - Method: Plain Text String (eg. '321asdFDSA0...etc')
xxxxxxxxxx
UPDATE mysql.user
SET Authentication_string=PASSWORD('PASSWD_TEXT')
WHERE user='USER' AND host='HOST';
FLUSH PRIVILEGES;
How To Update MySQL Password - Method: Password Hash String (eg. '*E9DA6A838E...etc')
xxxxxxxxxx
UPDATE mysql.user
SET Authentication_string='PASSWD_HASH'
WHERE user='USERN' AND host='HOST';
FLUSH PRIVILEGES;
How To Reset Root Password
adds skip-grant-tables to /etc/my.cnf in the first [mysqld] section
xxxxxxxxxx
[[ $(grep skip.grant.tables /etc/my.cnf) ]] || sed -e 's/\([[]mysqld[]]\)/\1\nskip-grant-tables/' /etc/my.cnf
Restart MySQL/MariaDB
xxxxxxxxxx
systemctl restart mysql
Connect to MySQL
xxxxxxxxxx
mysql
Enable Privileges Again
xxxxxxxxxx
FLUSH PRIVILEGES;
Update Root Password & SHUTDOWN MySQL
xxxxxxxxxx
ALTER USER 'root'@'localhost' IDENTIFIED BY 'nEw_pAssWoRd!'; SHUTDOWN;
Remove skip-grant-tables from /etc/my.cnf
xxxxxxxxxx
sed -i '/skip.grant.tables/Id' /etc/my.cnf
Start MySQL/MariaDB
xxxxxxxxxx
systemctl restart mysql
Tested Working On The Following Version:
• Server version 5.7
Tested Working On Prior Versions with modification - Prior Versions Use "Password" instead of "Authentication_string" to identify the password field so modify the above commands accordingly.
• Server version 5.5.5-10.3.35-MariaDB
xxxxxxxxxx
UPDATE mysql.user SET authentication_string=PASSWORD("rootpass") WHERE User='root';