I run into an issue today with PostgreSQL. I had manually entered a row into a table and it caused the primary key to fall out of sequence. To reset the primary key sequence ID on the PostgreSQL table I used the setval and pg_get_serial_sequence functions. Source: How to reset postgres’ primary key sequence when […]
SQL
Fixing MySQL Error 1153 – Got a packet bigger than ‘max_allowed_packet’ bytes
To fix, “MySQL Error 1153 – Got a packet bigger than ‘max_allowed_packet’ bytes” on Ubuntu edit your /etc/mysql/mysql.conf.d/mysqld.cnf. Once you have opened the file, increase the max_allowed_packet to a value that works for your environment. For example, in a local development environment, 100M can work. Then restart MySQL. Resources https://stackoverflow.com/questions/93128/mysql-error-1153-got-a-packet-bigger-than-max-allowed-packet-bytes
How to Display and Debug All Database Queries Made by WordPress
When working with WordPress you will eventually have the question, “How do I display all database queries made by WordPress?” In your wp-config.php file add the following: By setting SAVEQUERIES to true the wpdb global instance will store all the database queirs you make; this will allow you to inspect the number of queires each […]
Disable MySQL Strict Mode and NO_ZERO_DATE Errors in Laravel Homestead
If you are using MySQL 8 or 5.7, on Laravel Forge, for example, use the command sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf. The options file /etc/mysql/conf.d/mysql.cnf is not the .cnf file we are using in this particular instance. Then add the sql_mode options you need and wrap them in quotes under the [mysqld] group. The sql_mode options needed […]
Import and Export MySQL and PostgreSQL
There are many ways to export and import data from a database. You can use a Mac client like Sequal Pro for MySQL, for example. You can do the same for PostgreSQL, though I have not settled on a Mac client for PostgreSQL. Mac clients aside, you need can import and export your database SQL […]
Raw PHP and MySQL Eager Loading
Working with complicated and joined data sets can be tricky for MySQL database performance. For example, What if you need to load multiple authors and their books from a database. How would you work around the N+1 problem and avoid unnecessary queries to the database without an expensive join statement? The answer is quite simple. […]