O'Reilly logo
  • Thomas Kelly thinks this is interesting:

mysql -u root -p -e "SET PASSWORD FOR 'root'@'127.0.0.1' PASSWORD('new_pwd');" mysql -u root -p -e "SET PASSWORD FOR 'root'@'localhost' PASSWORD('new_pwd');"

From

Cover of Learning MySQL and MariaDB

Note

Using MariaDB 10.1.x, must include an equals sign after the user designation, as such:
mysql -u root -p -e “SET PASSWORD FOR ‘root’@’127.0.0.1’ = PASSWORD(‘new_pwd’);”