If MySQL is installed on a machine for which hostname does not return the fully-
qualified hostname, subsequent attempts to access MySQL using the hostname as
the MySQL 'root' user will fail.
The mysql_install_db script, when creating the authorization tables in the mysql
database, uses the `hostname` system call to get the hostname. MySQL checks to
make sure it's a valid hostname by checking to see if it resolves OK, and that's
it. So, we end up with hosts for the 'root' user in the user table like this:
% mysql/bin/mysql -u root -BN -e 'SELECT Host FROM mysql.user WHERE User = "root"'
localhost
vdt-rhas3-ia32
However, when attempting to connect to MySQL using the -h (hostname) option, it
seems that MySQL resolves the hostname to its fully-qualified hostname (FQHN)
before authorizing:
% mysql/bin/mysql -u root -h vdt-rhas3-ia32
ERROR 1045 (28000): Access denied for user 'root'@'vdt-rhas3-ia32.cs.wisc.edu' (using password: NO)
So, our idea is to add the FQHN as a host for the 'root' user when the FQHN is
not already in the table. We can probably do this is configure_mysql, although
it's not clear exactly where would be best.
To see if the FQHN is present or not, you can run a command like this:
mysql/bin/mysql -u root -BN -e 'SELECT Host FROM mysql.user WHERE User = "root" AND Host != "localhost"'
If the FQHN is absent from the output, it is absent from the user table.
Connecting to MySQL with the 'root' user, the correct GRANT statement looks like
this:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'vdt-rhas3-ia32.cs.wisc.edu' WITH GRANT OPTION
(Obviously, replace the hostname with the real FQHN.)