change mysql user code example

Example 1: alter user root mysql

ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPassword';

Example 2: mysql set password for user

# `SET PASSWORD FOR <user> = PASSWORD('<plaintext_password>')` is deprecated
SET PASSWORD FOR <user> = '<plaintext_password>';
FLUSH PRIVILEGES;

Example 3: change user mysql

[madegow@fedora20 ~]$ mysql -u root -p
Enter password: 
...
MariaDB [(none)]> select user()
-> ;
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

MariaDB [(none)]> system mysql -u madegow -p
Enter password: 
...
MariaDB [(none)]> select user();
+-------------------+
| user()            |
+-------------------+
| madegow@localhost|

Tags:

Sql Example