Q:

Cannot import SQL file when the database name contains an underscore

I'm attempting to import an SQL file into a MySQL database using the following command;
mysql --user example -p --database example_database < example.sql

This returns the error:
ERROR 1044 (42000) at line 22: Access denied for user 'example'@'%' to database 'example'

Notice the database name has trimmed everything after the underscore. The connection details are definitely correct as I can connect to MySql using the following command:
mysql --user example -p --database example_database

Any ideas why this is happening?

A:

A likely explanation for the observed behavior is that the example.sql file contains a statement:
  USE example;

The error is thrown when that statement is being executed because user 'example'@'%' is not granted privileges on that database.
(I don't believe the --database option value is being trimmed right before an underscore character. The conjecture about the underscore in the database name is a red herring.)

