OK - After much trial and error, I've solve this one. You need to escape the underscore in the GRANT statement line. You do NOT need to escape the underscore in the CREATE DATABASE line. Go figure. so this code gets it right (the change is in red below):
Code:
CREATE DATABASE `username1_dbname`;
GRANT ALL ON `username1\_dbname`.* TO 'username1_foo'@'localhost' IDENTIFIED BY 'lskdfj';
FLUSH PRIVILEGES;
I have no idea why this is necessary. Again, the original version works just fine, it's just that the graphical cPanel database admin user page does not show the connection between the username and the db name unless you do the escaping as above. Quirky.