Tuesday, January 1, 2013

How to install MySQL succesfully on a Raspberry Pi

For those starting to learn MySQL and want to install it on a Raspberry Pi: there is a little gotcha you should be aware of.

Disclaimer: Only run command if you know what it does. Always make sure you have backups of your important data.

First you need to put the official Raspbian image on your SD card and then boot the Raspberry Pi.

Then if you try to install mysql with "sudo apt-get install mysql-server-5.5" this will fail. The reason for this is that the filesystem on the SD card will become full. This can be seen by running the "df -h" command.

The SD card is probably 4GB. The filesystem will be around 1.9GB. This was done to make it fit on 2GB cards. To stretch the filesystem to complete 4GB you need to run "sudo raspi-config" and choose the "expand_rootfs" option. Then you need to reboot.

Now "df -h" should tell you that the filesystem has much more free space.

But your MySQL installation failed. So you run "sudo apt-get purge mysql-server-5.5" and remove the mysql-server-5.5 package and all related files.

If you would try to reinstall MySQL with "sudo apt-get install mysql-server-5.5" it would fail again. This is due to the data in /var/lib/mysql which belongs to the failed installation. You should remove that data "rm -rf /var/lib/mysql" and then install mysql again "sudo apt-get install mysql-server-5.5".

Now you should have a basic MySQL installation. You could use the "mysql_secure_installation" command to secure your installation.

7 comments:

  1. It is still giving me the
    "[FAIL] Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!"
    what do i do?

    ReplyDelete
  2. Same here:
    It is still giving me the
    "[FAIL] Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!"
    what do i do?
    ----
    Putty LOG'S:

    pi@rpi01:~$ sudo apt-get purge mysql-server-5.5
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
    libblas3gf liblapack3gf
    Use 'apt-get autoremove' to remove them.
    The following packages will be REMOVED:
    mysql-server-5.5*
    0 upgraded, 0 newly installed, 1 to remove and 14 not upgraded.
    1 not fully installed or removed.
    After this operation, 30.9 MB disk space will be freed.
    Do you want to continue [Y/n]? y
    (Reading database ... 58655 files and directories currently installed.)
    Removing mysql-server-5.5 ...
    Stopping MySQL database server: mysqld.
    Purging configuration files for mysql-server-5.5 ...
    Processing triggers for man-db ...
    pi@rpi01:~$ rm -rf /var/lib/mysql
    rm: cannot remove `/var/lib/mysql': Permission denied
    pi@rpi01:~$ sudo rm -rf /var/lib/mysql
    pi@rpi01:~$ sudo apt-get install mysql-server-5.5
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
    libblas3gf liblapack3gf
    Use 'apt-get autoremove' to remove them.
    Suggested packages:
    tinyca
    The following NEW packages will be installed:
    mysql-server-5.5
    0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
    Need to get 1,658 kB of archives.
    After this operation, 30.9 MB of additional disk space will be used.
    Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main mysql-server-5.5 armhf 5.5.31+dfsg-0+wheezy1 [1,658 kB]
    Fetched 1,658 kB in 1s (1,306 kB/s)
    Preconfiguring packages ...

    ...

    ReplyDelete
  3. Package configuration
    Configuring mysql-server-5.5

    While not mandatory, it is highly recommended that you set a password for the MySQL administrative "root" user.
    If this field is left blank, the password will not be changed.

    New password for the MySQL "root" user: Package configuration
    ┌──────┤ Configuring mysql-server-5.5 ├───────┐
    │ Repeat password for the MySQL "root" user: │
    Selecting previously unselected package mysql-server-5.5.
    (Reading database ... 58572 files and directories currently installed.)
    Unpacking mysql-server-5.5 (from .../mysql-server-5.5_5.5.31+dfsg-0+wheezy1_armhf.deb) ...
    Processing triggers for man-db ...
    Setting up mysql-server-5.5 (5.5.31+dfsg-0+wheezy1) ...
    Stopping MySQL database server: mysqld.
    130715 5:36:01 [Note] Plugin 'FEDERATED' is disabled.
    130715 5:36:01 InnoDB: The InnoDB memory heap is disabled
    130715 5:36:01 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    130715 5:36:01 InnoDB: Compressed tables use zlib 1.2.7
    130715 5:36:01 InnoDB: Using Linux native AIO
    130715 5:36:01 InnoDB: Initializing buffer pool, size = 128.0M
    130715 5:36:01 InnoDB: Completed initialization of buffer pool
    130715 5:36:01 InnoDB: highest supported file format is Barracuda.
    130715 5:36:01 InnoDB: Waiting for the background threads to start
    130715 5:36:02 InnoDB: 5.5.31 started; log sequence number 1595675
    130715 5:36:02 [ERROR] /usr/sbin/mysqld: Can't find file: './mysql/user.frm' (errno: 13)
    ERROR: 1017 Can't find file: './mysql/user.frm' (errno: 13)
    130715 5:36:02 [ERROR] Aborting

    130715 5:36:02 InnoDB: Starting shutdown...
    130715 5:36:03 InnoDB: Shutdown completed; log sequence number 1595675
    130715 5:36:03 [Note] /usr/sbin/mysqld: Shutdown complete


    Package configuration
    ───────────────┤ Configuring mysql-server-5.5 │ Unable to set password for the MySQL "root" user An error occurred while setting the password for the MySQL administrative user. This may have happened because the account already has a password, or because │
    │ of a communication problem with the MySQL server.
    │ You should check the account's password after the package installation.
    │ Please read the /usr/share/doc/mysql-server-5.5/README.Debian file for more information. │
    /etc/init.d/mysql: WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz ... (warning).
    Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!
    invoke-rc.d: initscript mysql, action "start" failed.
    dpkg: error processing mysql-server-5.5 (--configure):
    subprocess installed post-installation script returned error exit status 1
    Errors were encountered while processing:
    mysql-server-5.5
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    pi@rpi01:~$

    ReplyDelete
  4. ups http://mirrordirector.raspbian.org/raspbian/pool/main/m/mysql-5.5/mysql-comoom.... 404 not Found

    ReplyDelete
    Replies
    1. Maybe the package info is outdated? Just run "sudo apt-get update" and try again.

      Delete