MySQL not writing to database

Posted September 14, 2021 200 views
NginxUbuntuMySQLPHPLEMPUbuntu 20.04

I followed along with the Digitalocean LEMP stack tutorial and everything works perfectly. My app is running smoothly, but for some reason it can’t seem to write to my database. It reads and even updates the database without problems, but whenever I try to take any action that should write to the database it doesn’t work. It connects to the database, executes the query and returns the necessary data, but nothing has been written to the database.

I’ve followed the tutorial to the tee on Ubuntu 20.04. But then I also tried giving the MySQL user full privileges on the database, but still nothing. I’ve removed the user and added a new one, gave privileges, flushed privileges, and restarted MySQL too. Still nothing.

I thought I’d enable the MySQL error logging to see what errors pop up, but non of the tutorials I found worked.

Does anyone perhaps know what could be the issue here? And if not, is there a working/updated tutorial on Digitalocean that will help me to enable MySQL error logging so I can try and figure it out myself?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


I would recommend making sure that you’ve granted all privileges to the new user that you’ve created:

GRANT ALL ON example_database.* TO 'example_user'@'%';

If this still does not help, can you share an example of the problematic code snippet that you are using the insert data into the database?


  • Hey @bobbyiliev,

    Thanks for your response 🙏

    I’ve tried what you have there, as well as:

    GRANT ALL PRIVILEGES ON example_database.* TO 'example_user'@'%';

    but it still didn’t work.

    So my query looks like this (using PDO).

    INSERT INTO table_name(email, name, definition, use_case, use_case2, idiom, idiom2, synonyms, antonyms, plural, small, extensions, abbreviation, degrees, translation, origin, sources, status) VALUES(:email, :name, :definition, :use_case, :use_case2, :idiom, :idiom2, :synonyms, :antonyms, :plural, :small, :extensions, :abbreviation, :degrees, :translation, :origin, :sources, :status);

    It works fine in my dev environment, although that’s on Apache, while this is on Nginx. I’ll look into my written code a little more too and see if I can find anything that might be messing around in production.

  • Actually @bobbyiliev… Nevermind. I found the error. It’s because certain column values didn’t have a default value set. Sorry about that and thanks for the help anyway.