How to set a non-empty password to the `root` MySQL user in Ubuntu?

mysql -u root
use mysql;
update user set authentication_string=PASSWORD("mynewpassword") where User='root';
flush privileges;
quit

support.rackspace.com/how-to/mysql-resetting-a-lost-mysql-root-password

See also: How to fix non-root login to MySQL in Ubuntu?