in reply to Fetch Mysql huge database
Using SELECT DISTINCT is exactly what you need here though. Since that is running too long, the issue lies at the MySQL database instead. Here are some ideas that might help you.
Check if there is an index on the column UserName.
Check if there is enough RAM in the machine where the database is at. If there isn't, MySQL will create a temporary table on disk, which is generally very slow.
Check if your query is blocked by other queries that operate on that table using SHOW FULL PROCESSLIST on the database.