Well, none of the above well-intentioned answers worked for me, on Ubuntu 20.04-6. Turns out, mysqld's default socket file path doesn't exist when mysqld isn't running, and mysqld_safe doesn't create it. So the answer is to create the socket directory, and also set ownership to Unix user mysql-
$ sudo systemctl stop mysql.service
$ sudo mkdir /var/run/mysqld
$ sudo chown mysql.mysql /var/run/mysqld
$ sudo mysqld_safe --skip-grant-tables --socket=/var/run/mysqld/mysqld.sock &
$ mysql -u root
> *proceed with mysql password change*
> ^D
$ mysqladmin shutdown
$ sudo systemctl start mysql.service
This worked for me. Now you should be able to go about your mysql business as usual, as I was.
UPDATE- if you've just installed MySQL 8.0+, there's now a straightforward way to set the root password: Securing the Initial MySQL Account