Subscribe to How-To Geek

Install MySQL Server 5 on Ubuntu

Installing MySQL 5 Server on Ubuntu is a quick and easy process. It almost feels like it should be more difficult.

Open a terminal window, and use the following command:

sudo apt-get install mysql-server

If you are running PHP you will also need to install the php module for mysql 5:

sudo apt-get install php5-mysql

To create a new database, use the mysqladmin command:

mysqladmin create <databasename>

See, really easy!

The Geek is the founder of How-To Geek and a geek enthusiast. This article was written on 12/28/06 and tagged with: Adding Software, MySQL, Ubuntu

Daily Email Updates

You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


Name:
Email:
Similar Articles Featured Wiki Articles
Latest Software Reviews Quick Linux Tips
Geek Arcade Popular Forum Threads

Comments (28)

  1. miyaka

    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
    Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!

  2. Tom

    The last step posted above does not work:

    Here is the output:
    honey@honey:~$ mysqladmin create test
    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘honey’@'localhost’ (using password: NO)’

  3. iskall

    This tutorial is great except like all the others trying to follow this tutorial gets the same exception/errors, this means you have forgotten some steps, how to start the server. Please update this tutorial and correct it.

  4. Ray Ojinaga

    The command for installing mysql-server-5.0 seems to work, but your instructions are lacking detail. For example, how do you start and stop the server and client? Furthermore, are environment variables required? Most computer users don’t want to hack and fuss with their machines for all eternity. I realize that a complete tutorial on mysql is out of the question. However, enough information should be provided so that mysql can be installed, configured, and tested. Additionally, you should provide instructions for those users that download the mysql archive directly to their desktop and wish to install it from their.

  5. OJ

    Start your MySQL server by using the command:
    /etc/rc.d/init.d/mysql start

    you can also stop it via the command:
    /etc/rc.d/init.d/mysql stop

    Surprisingly enough, a Google search for “mysql start” returned this in the first couple of results.

  6. Octavius

    Previous example for Mysql start-stop don’t work for me. I using Ubuntu 7.10.
    Good example for me is:

    Start MySQL server by using the command:
    sudo /etc/init.d/mysql start

    Stop MySQL server by using the command:
    sudo /etc/init.d/mysql stop

    Sorry for my english…

  7. Mouse

    A google search does indeed tell me that I should use the command:
    /etc/rc.d/init.d/mysql start

    However, as a newcomer to both MySQL and Ubuntu/Linux this doesn’t help me – I simply get the new error “bash: /etc/rc.d/init.d/mysql: No such file or directory”. Googling that error doesn’t help either; the top results seem to be people who have managed to edit their conf files and have made their installation *stop* working; I haven’t yet got as far as making it work in the first place.

    I have installed the MySQL client and server through Synaptic, but haven’t yet managed to work out how to start the server. I’m afraid I have to agree with the previous comments on this article – there simply isn’t enough information to enable a newbie to work out how to begin. If you’re not a newbie, you probably don’t need this article at all. More details here would be wonderful!

    (And comments like “see, really easy!” don’t help newbies’ frustration levels – I know that what I want to do is simple; I know the rest of the world finds it easy; but knowing that it’s simple doesn’t help me work out what on earth it is I need to type/edit/install/mess about with to make this work).

  8. Fernando Las

    i try this
    sudo apt-get install mysql-server
    but dont work
    NOT FOUND

  9. Conor Kirkpatrick

    When I do this I get this error:

    conorkirk@Conor-WebServer:~$ sudo mysqladmin create conor_data
    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@'localhost’ (using password: NO)’
    conorkirk@Conor-WebServer:~$

    The tutorial didn’t say how to set up Mysql users. :(

  10. keshet

    apt-get worked fine for me. Just pick a password for root.

    Startup & shutdown: System Menu -> Administration -> Services
    You control mysql from here.

    You can do ‘ps ax | grep mysql’ in a terminal window to see if it is running (you should see /usr/sbin/mysqld running).

    Install MySQL Administrator from Add/Remove to create & manage databases with a nice GUI.

  11. Casey Wise

    Very helpful. I’m working in Ubuntu 8.04 and it went well for me. Thanks for the tutorial!

  12. Gareth Evans

    mysqladmin -u root -p create

    and enter the root paaword you set in the installation of mysql

  13. ab_iron

    And if you need to connect to MySQL remotely comment out the line:

    bind-address = 127.0.0.1

    in your /etc/mysql/my.cnf file, followed by a restart.

    ab_iron

  14. Trevor

    I installed mysql on Ubuntu (whatever the latest version is) and tried to migrate some databases from my mac. Big mistake. Now mysql is screwed completely, won’t start. I can uninstall it, I can reinstall it, but it will not start. None of the suggestions on this page make any difference.

    root@nelson:~# /etc/init.d/mysql start
    * Starting MySQL database server mysqld
    …done.
    /usr/bin/mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘debian-sys-maint’@'localhost’ (using password: YES)’

    root@nelson:~# mysqladmin -u root -p create
    Enter password:
    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@'localhost’ (using password: YES)’

    I’m completely hosed. Apparently I can’t even wipe it and start over. Any ideas?

  15. mike

    I had the same problems then you guys have already mention but we fergot something very simple, i had installed the client end of the mysql, but i had not installed the mysql SERVER 5.5, so i could not connected to the server even after tapying the password, because it was not installed, ahh, so we need to install the
    sudo apt-get install mysql-server 5.0
    sudo apt-get install mysql-Client 5.0

  16. Spoom

    Trevor: Take a look at http://dev.mysql.com/doc/refma.....sions.html , it details how to reset the root password.

  17. Dave

    I installed Ubuntu then mysql from the packages option. After installation I access mysqladministrator and mysql queries from the applications tab. When I select either, I am required by the mssql administrator GUI to enter a host name, password and userID. I tried the local host (127.0.0.1)and the network host (127.0.1.1) with no luck. Any ideas?

  18. tjslager

    It was easy to install. But now I can’t find it on my computer. It’s not on my Applications tab. When I look in Add/Remove Applications, it is not listed. I need to start it so I can peruse the help files, since I’m a total novice. I just want mysql so that I can install and practice using drupal…

  19. phanleson

    oh, thank you for this posted, i very like ubuntu and i fell interested with this tutorial and with comments of visitor blog !
    Thank !

  20. dando

    not bad but little corrections
    “/usr/bin/mysqladmin: connect to server at ‘localhost’ failed”

    you must switch to user /no root /
    type:
    su user
    sudo /etc/init.d/mysql start
    type password for user

    sudo mysqladmin -u root -p create mydatabase

  21. Roman

    I don’t understand why all of you have such problem (with starting of mysql).
    I using ubuntu 8.1 and after downloading the mysql just entered > mysql and all work fine. The mysql well started and you able to launch any commands (like CREATE TABLE or SHOW DATABASES)

  22. Andy James

    I had same problem with mysql not starting automatically. Install works fine and can run mysql without problems. When I reboot the PC I get the message

    “/usr/bin/mysqladmin: connect to server at ‘localhost’ failed”

    Using the advice above to

    you must switch to user /no root /
    type:
    su user
    sudo /etc/init.d/mysql start
    type password for user

    It now works fine. I just need to get this to run on startup

  23. MIke

    If you are using Ubuntu Hardy Heron try using:
    /usr/bin/mysql_setpermission to set the database user permissions. It is very simple and straight forward.

    In order to get mysql to start when the system start you need to place a link from /etc/init.d/mysql in the appropriate rc.d directory. Since you are looking for mysql to start in the gnome environment you will want to set the link in the /etc/rc5.d directory.

    I have found that leaving the root password blank on your local system helps with development.

  24. Zac

    Thanks. Works great!

  25. janardhan

    Thanks
    Its helping a lot to implement things, keep it up.

  26. Shiv

    Thanks Geek Boy !!

    any ideas for MySQL WorkBench ?

  27. Matthew

    any tips on improving performance for a dedicated ubuntu mysql server?

  28. Raghu

    Hi all,
    Thanks for all the tips. But I am encountering a prob from few days. Whenever I try to install something, it starts to install nicely but later the below command appears on terminal
    Setting up acidlab (0.9.6b20-22) …
    This command remains as it is. Even though one day I left comp on for 8 hours or so allowing terminal to set acidlab but it didn’t. Now I was installing mysql everthing went rite It also prompted me to enter password for root. (But as mike as commented I didn’t enter any password) after that this line appeared on terminal Setting up acidlab (0.9.6b20-22) …
    and terminal is not progressing at all. So please help me (As I need to submit my DBMS project)


Leave a Comment




Leave your friendly comment here.

If you have a computer help question, click here to leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Sponsored Links
Getting Started
About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
Cmd.exe
Dpupdchk.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. All Rights Reserved.