MySQL · December 20, 2023

How to Fix MySQL Error 1285 - SQLSTATE: HY000 (ER_WARN_HOSTNAME_WONT_WORK) MySQL is started in --skip-name-resolve mode; you must restart it without this switch for this grant to work

How to Fix MySQL Error 1285 - SQLSTATE: HY000 (ER_WARN_HOSTNAME_WONT_WORK)

MySQL is a popular open-source relational database management system used by many websites and applications. However, sometimes users may encounter errors while working with MySQL. One such error is MySQL Error 1285 - SQLSTATE: HY000 (ER_WARN_HOSTNAME_WONT_WORK). This error occurs when MySQL is started in --skip-name-resolve mode, and you try to grant privileges to a user based on their hostname. In this article, we will explore the causes of this error and provide step-by-step instructions on how to fix it.

Causes of MySQL Error 1285

The main cause of MySQL Error 1285 is the --skip-name-resolve mode. When MySQL is started with this mode enabled, it disables the hostname resolution for incoming connections. This means that MySQL will not perform any DNS lookups to resolve the hostname of the connecting clients. As a result, when you try to grant privileges to a user based on their hostname, MySQL throws the ER_WARN_HOSTNAME_WONT_WORK error.

Fixing MySQL Error 1285

To fix MySQL Error 1285, you need to restart MySQL without the --skip-name-resolve switch. Follow the steps below to resolve the issue:

Step 1: Stop the MySQL Service

Before making any changes, stop the MySQL service to ensure a clean restart. You can use the following command to stop the MySQL service:

sudo service mysql stop

Step 2: Edit the MySQL Configuration File

Next, you need to edit the MySQL configuration file to remove the --skip-name-resolve switch. The configuration file is usually located at /etc/mysql/mysql.conf.d/mysqld.cnf or /etc/my.cnf. Open the file using a text editor:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Find the line that contains the --skip-name-resolve switch and comment it out by adding a '#' at the beginning of the line. Save the changes and exit the text editor.

Step 3: Start the MySQL Service

After editing the configuration file, start the MySQL service again:

sudo service mysql start

Step 4: Grant Privileges

Once MySQL is restarted without the --skip-name-resolve switch, you can now grant privileges to users based on their hostname without encountering the ER_WARN_HOSTNAME_WONT_WORK error. Use the GRANT statement to assign the necessary privileges to the user:

GRANT privileges ON database.table TO 'username'@'hostname';

Replace 'privileges' with the specific privileges you want to grant, 'database.table' with the database and table name, 'username' with the user you want to grant privileges to, and 'hostname' with the hostname of the user.

Summary

In conclusion, MySQL Error 1285 - SQLSTATE: HY000 (ER_WARN_HOSTNAME_WONT_WORK) occurs when MySQL is started in --skip-name-resolve mode, and you try to grant privileges to a user based on their hostname. To fix this error, you need to restart MySQL without the --skip-name-resolve switch. By following the steps outlined in this article, you can resolve the issue and grant privileges to users without any problems.

For more information about VPS hosting and how it can benefit your website or application, visit Server.HK. Our Hong Kong VPS hosting solutions are reliable, secure, and tailored to meet your specific needs.