Subscribe to RSS

How to install MySQL on Ubuntu/Debian

It may seem easy for some, but for others, installing MySQL on Ubuntu or Debian Linux is not an easy task. This article explains to you how to install the MySQL Server and Client packages on a Ubuntu/Debian system.

First of all, make sure your package management tools are up-to-date. Also make sure you install all the latest software available.

sudo apt-get update
sudo apt-get dist-upgrade

After a few moments (or minutes, depending on the state of your system), you’re ready to install MySQL.

By default, recent Ubuntu/Debian systems install a MySQL Server from the 5-branch. This is a good thing, so don’t worry.

First, install the MySQL server and client packages:

sudo apt-get install mysql-server mysql-client

When done, you have a MySQL database read to rock ‘n roll. However, there’s more to do.

You need to set a root password, for starters. MySQL has it’s own user accounts, which are not related to the user accounts on your Linux machine. By default, the root account of the MySQL Server is empty. You need to set it. Please replace ‘mypassword’ with your actual password and myhostname with your actual hostname.

sudo mysqladmin -u root -h localhost password 'mypassword'
sudo mysqladmin -u root -h myhostname password 'mypassword'

Now, you probably don’t want just the MySQL Server. Most likely you have Apache+PHP already installed, and want MySQL to go with that. Here are some libraries you need to install to make MySQL available to PHP:

sudo apt-get install php5-mysql

Or for Ruby:

sudo apt-get install libmysql-ruby

You can now access your MySQL server like this:

mysql -u root -p

Have fun using MySQL Server.

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Technorati
  • BlinkList
  • E-mail this story to a friend!
  • Facebook
  • Live
  • MisterWong
  • Netvouz
  • NewsVine
  • Slashdot
  • SphereIt

3 Comments

  1. Lars
    Posted 31 May, 2008 at 09:17 | Permalink

    Surely fine advices!
    I’m a MySQL/PHP user from the old ugly Windows environment and now I’m migrating to Linux/Ubuntu.
    And of cause there are a lot of beginner’s problems.
    Can you give me some advices to this problem:

    1) MySQL. In short: How to COMPLETELY get rid of a malfunctioning MySQL-installation ?
    Background: After installing mysql-server and client I tried to set the root password, starting with this:
    :~$ sudo mysql -uroot -p
    [sudo] password for lars:
    Enter password: [I did / I even tried not to with the same results]
    ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: YES)
    …..
    Even after I removed, reinstalled and started the server like this:
    $ sudo apt-get –purge remove mysql-server
    $ sudo apt-get install mysql-server
    $ sudo mysqld
    the same problem persisted when I tried to login.
    …..
    I also run the script:
    $ sudo /usr/bin/mysql_install_db, but the first reported problem persisted.
    …..
    Would be delighted for some suggestions…
    Best Regards /Lars

  2. nitin
    Posted 27 June, 2008 at 13:52 | Permalink

    Hi Lars,
    please read the above guide lines.the root password can be set
    two ways.

    1.at the time of installation it will ask ,that time u give it or leave it blank u can change after installation.

    2.after installation you just run the command

    sudo mysqladmin -u root -h localhost password

    ~Nitin

  3. paroo
    Posted 28 June, 2008 at 11:27 | Permalink

    thanks a lot
    searched many sites but was in vain

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*