error 1045(28000):anonymous user problem
Here is what you are missing


Connecting with user a via a socket is the same as connecting with user a via localhost.
Connecting with a socket will not use TCP/IP


If you are going to explicitly using a hostname, you must use TCP/IP with port 3306 and no socket

mysql -ua -p -h hosta --protocol=tcp -P3306


I have discussed using --protocol=tcp in my earlier posts


Jul 16, 2015 : mysql.sock not generated when starting MySQL server using XAMPP
Jul 13, 2015 : mysql restart issue after move database
Jul 11, 2013 : Rare error lasts only a second &quot;Can&#39;t connect to local MySQL server through socket &#39;/tmp/mysql.sock&#39; (146)&quot; 146=ECONNREFUSED
Mar 28, 2013 : MySQL - ERROR 1045 (28000): Access denied for user


You need to delete blank users, blank hosts, and blank passwords from mysql.user

DELETE FROM mysql.user WHERE user = '';
DELETE FROM mysql.user WHERE host = '';
DELETE FROM mysql.user WHERE password = '';
FLUSH PRIVILEGES;