MySQL

Example usage - if a field is a varchar and you need to sort by a number. It will sort it alpabetically, instead of numerically. Type casting will convert it to an altenative data type.

Here is an example of how to select some data from a table on one database and insert into a table of a different database. I assumes that you are using the same mysql connection.

The MySQL USE command is used to select the appropriate database at the appropriate time. database1 is where the data is being selected from and database2 is where it is inserted to.

Modify an existing column to make it auto increment.

Backup a database from cron. Add the following to the cron tab.

This is for the basic snippet to connect to a MySQL database.

Add new user to MySQL database. First, log into the MySQL console, and then run the following command, replacing databasename, username and password.

Simple command to backup a MySQL database. Run from Linux command line.

MySQL Server Has Gone Away Error - Cause & Solution

The MySQL Server has gone away error can happen when trying to restore a database. There are a few possible causes for this and one of the most likely is that the database is very big in size and the packet size in MySQL is not big enough.

Restore MySQL database in WampServer

If you are running WampServer on your local machine, it can be a bit tricky to restore a MySQL database. You need to do it from the Windows command line (DOS prompt), rather then the MySQL console command line. The actual MySQL restore command is slightly different to normal and you need to make sure you are in the right directory first.

Reset auto increment after deleting a table row

It is often the case that a column such as the ID column on a table will auto increment. This simply means that the next insert into the table will have an ID that is one more then the previous one and therefore all ID's will be unique.