Notes & Snipsets

#1. How to reset the post ID increment WordPress

Go to phpMyAdmin, make sure your that on my wp_posts and wp_postsmeta tables are only information about the 10 real posts IDs, from the mysite/wp-admin/export.php I exported all the posts (10 of them), then run the following SQL query on phpMyAdmin.

DELETE FROM wp_posts;

DELETE FROM wp_postmeta;

TRUNCATE TABLE wp_posts;

TRUNCATE TABLE wp_postmeta;

#2. Linux Command to unzip/extract a .tar.gz file

Type man tar for more information, but this command should do the trick:

tar -xvzf community_images.tar.gz

To explain a little further, tar collected all the files into one package, community_images.tar. The gzip program applied compression, hence the gz extension. So the command does a couple things:

  • f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
  • z: tells tar to decompress the archive using gzip
  • x: tar can collect files or extract them. x does the latter.
  • v: makes tar talk a lot. Verbose output shows you all the files being extracted.

Extra :
tar -xvf <.tar file> or <.tar.xz file>
tar -xzvf <.tar.gz file>
tar -xjvf <.tar.bz2 file>

#3. How do I import an SQL file using the command line in MySQL?

I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the command line.

Try:
mysql -u username -p database_name < file.sql

Check MySQL Options.

Note-1: It is better to use the full path of the SQL file file.sql.

Note-2: Use -R and --triggers to keep the routines and triggers of original database. They are not copied by default.

Note-3 You may have to create the (empty) database from mysql if it doesn’t exist already and the exported SQL don’t contain CREATE DATABASE (exported with --no-create-db or -n option), before you can import it.