MySQL Tutorials

Install LAMP on Ubuntu 12.04 (Linux, Apache, MySQL, PHP)

In this tutorial we will look at how to install Apache, MySQL, and PHP on an Ubuntu 12.04 system using the command line. This set of packages together is called a LAMP server or a LAMP stack. The LAMP stack is the most common form of software stack used on web servers today.

Apache is used to serve web pages, PHP works with Apache to enable you to create dynamic web pages, and MySQL works with PHP to enable it to communicate with a database backend. Note that any of these packages can be installed separately but for running a dynamic website, they are usually installed together.

MySQL Error 1064 Explained

MySQL Error 1064 is a general parse error that the query parser encountered when processing the SQL statement before execution. This error is basically saying that you have some sort of syntax error in your SQL statement.

The MySQL server is very helpful and gives an error message of the following form:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near %s at line %d.

Change MySQL Root Password in Ubuntu

In this tutorial we will look at how to change the MySQL root password in Ubuntu Linux if you have forgotten it or inherited a server and never knew it in the first place. To change the MySQL root password in Ubuntu you will need superuser privileges, i.e. root access, on the system. The following guide works on Ubuntu 10.04, 10.10, 11.04, 11.10, and possibly 12.04.

Check MySQL version

In this tutorial, we will look at how to check the version of the MySQL server that is running on a system. Different versions of MySQL behave differently and also have different features so it is important to know what version is running for compatibility reasons.

There are 3 basic ways of checking the MySQL version. We can do it from the command line without logging in to the server, or we can do it in 2 ways (using SQL queries) after logging in to the server.

After logging in to the MySQL server, execute:

Change timezone on MySQL Server on Ubuntu

There are various ways of setting the timezone that the MySQL server uses. To explicitly set the timezone that MySQL uses on Ubuntu, all we have to do is add a line to the MySQL configuration file.

Note that it is usually not necessary to explicitly set the timezone for the MySQL server as MySQL is pretty good at getting the correct timezone from the system. Use the method outlined below only if you have special requirements.

Open a terminal, and run the following command as root:

nano /etc/mysql/my.ini

Restart MySQL Ubuntu

We may want to restart our MySQL server for a number of reasons. The most likely reason for wanting to restart our MySQL database server is to load new configuration settings.

It is a good idea to ensure that no users will be accessing the database server when you are performing the restart just in case the restart fails.

Always backup your configuration files before making any changes, as fouled up configuration files are the most likely causes of a failed restart.

MySQL Array to PHP Array

We saw in our MySQL Fetch Array Tutorial how to retrieve data from a MySQL database using PHP. This post is similar but will focus on converting the array that is returned from MySQL to a PHP array.

This technique is important as it allows us to convert data to a format that we can directly work on using PHP.

For the following examples, once again, we will assume that we have a database called "employees" and it contains an "employees" table as follows: