MySQL account passwords are administrative credentials for connecting to the server. They are separate from passwords your application stores for its own users. For MySQL accounts, ALTER USER is the preferred current statement for changing authentication settings.

ALTER USER 'usrname'@'localhost'
IDENTIFIED BY 'new-strong-password';
Avoid placing real administrative passwords in tutorial source, version control, URLs or command history.
ALTER USER CURRENT_USER()
IDENTIFIED BY 'new-strong-password';
ALTER USER 'user_id'@'localhost'
PASSWORD EXPIRE;
ALTER USER 'my_userid'@'localhost'
PASSWORD EXPIRE NEVER;
ALTER USER 'userid'@'localhost'
PASSWORD EXPIRE INTERVAL 30 DAY;
SET GLOBAL default_password_lifetime = 60;
A value of 0 disables automatic expiration through the global default:
SET GLOBAL default_password_lifetime = 0;
For application-user passwords, use PHP's password-hashing APIs rather than MySQL account-management statements. For database connection examples, see PDO/MySQLi connection.
Database connections · Error handling · PHP/MySQL overview · MySQL installation · Database administration
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.