Can’t create/write to file ‘/tmp/#sql_50e0_0.MYD’ (Errcode: 17)

While adding a SQL statement to Database sometimes we get an error as follows:

Can’t create/write to file ‘/tmp/#sql_50e0_0.MYD’ (Errcode: 17)

In order to remove the error.

Navigate to the root of the domain.

cd /home/username/public_html

Find the servers main php.ini file.

php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

Copy the file /usr/local/lib/php.ini to the public_html folder.

cp /usr/local/lib/php.ini  .

Open the php.ini file

Locate the line “session.save_path = /tmp

change it to “session.save_path = /home/username/public_html/tmp

Save and quit the file.

Now create the directory/home/username/public_html/tmp

mkdir /home/username/public_html/tmp

Assign respective ownership

chown username.username /home/username/public_html/tmp

Now assign full permissions to the folder

chmod 777 /home/username/public_html/tmp

Now try adding the SQL statement to the database. This should remove the error.