SEARCH

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!

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 12/28/06

Comments (62)

  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/refman/5.0/en/resetting-permissions.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)

  29. vamsi

    To Create Mysql user
    mysql_install_db
    mysqladmin -u root password YOURPASS

    mysql -u root -p
    Password: YOUR PASS
    mysql>create database DBNAME;
    mysql>\q

    TO import
    mysql torrentflux < omggggg.sql -u root -p
    Password: YOUR PASS

    Thanks

  30. Aaron M. Clay

    You need to be an admin in order to do some of these things. Try adding yourself to the sudoers file (terminal>visudo). Also, if you have problems, lifehacker is a great place to get tips on mysql as well.

  31. Aditya g jadhav

    hi
    nice i use web server as well as ubuntu 1st time :)
    nice info
    keep it up , yaar :D

    warm wish
    aditya g jadhav

  32. Bamboozled

    I got around the connection problem by typing ‘root’ (without quotes) as username instead of the username I am logged on as.

  33. Lupu

    for mi on Ubunt 9.04 worked ok:

    sudo apt-get install mysql-server
    sudo /etc/init.d/mysql start
    mysqladmin -u root -p create mydatabase

  34. Lupu

    not working on Ubuntu 9.10 Beta

  35. ken c

    If you don’t have the desire to “hack and fuss” with your computer then I suggest you abandon running sql, php , any sort of apache and well. hell, just don’t bother with a server much less a webserver in general, because you are in the wrong place. This stuff is not something that is a simple apt get install and press go…

  36. Jason

    My problem was that the mysql user was not created!

    Ubuntu: System -> Administration -> Users & Groups … created mysql (no group), it created mysql group … and then everything worked fine.

    Before creating the user, I got .sock errors, tried installing from binaries and source … and had the same problem across the board.

    After uninstalling everything to get away from MySQL 4.x, and perhaps some apt-get remove commands, following the simple apt-get install mysql-server did NOT work and I found myself digging through various .sock posts about creating files and a bunch of irrelevant shtuff.

  37. Calvin Fowler

    i am runnimg vmware with Ubuntu OS and MySQL on it. Mysql and everything work fine from within the Ubuntu/vmware setup, but I need to know how to connect to the mysql server from our website, I have uncommented the bind setting and I do have a separate ip address for my vmware setup, but I can/t connect to it using http or anything else. Anyone have any ideas.

    I need to run mysql from a linux based machine in order to comply with hipaa. I have a company that requires a linux machine for at rest encryption

  38. a6y

    it was good info xD

  39. Husen

    lots of thanks from Iraq…
    sudo /etc/init.d/mysql start
    worked fine for me.

  40. Andrew

    Ubuntu 10.4, :-)

    service mysql start

    service mysql stop

    service mysql restart

  41. Marc

    @ken c
    What you say is crap. Things shouldn’t be more complicated than they need to be, and this guide is just confusing people and making them frustrated, just to do something that should indeed simply be an apt-get install and go …

    I never understood people pretending what they know is really complex and difficult, when it actually isn’t.

    Remove this guide, it is not helping, thank you.

  42. Sapa2ler

    Just use phpmyadmin to administer your mysql database
    sudo apt-get install phpmyadmin

    Create password for mysql user root
    sudo mysqladmin -u root password YOURMYSQLROOTPASSWORD

    After doing that phpMyAdmin should be installed at http://localhost/phpmyadmin/

    Login to phpmyadmin
    user root
    password YOURMYSQLROOTPASSWORD

  43. baljit

    thx you so muchhhhhhhhhhhhhhhhhhhhhhhhhh

  44. Rami

    Dude,

    thanks for your posts, you might have no idea how much your quick howtos save time for linux newbies like me, i come from over 15 years of windows use, so just to change the pattern in which things are done is something very hard, anyways respect to whoever is beyond this site :).

    best regards,

    Rami

  45. Tylor

    You will want to do sudo /etc/init.d/mysql start if you are useing UBUNTU

    The first comment posted to start it is NOT for ubuntu or even debian at all. It is for the likes of redhat, centos, fedora, ect ect.

    Again… If you are useing UBUNTU – Any version: sudo /etc/init.d/mysql start

    :) have fun.

  46. it works.just few missing pieces

    the latest version installs mysql client and server.
    to login just do
    mysql -uroot -p .enter password u gave while installing.

    create user and other permissions by

    mysql> create user santhosh identified by ‘yourpwd';
    Query OK, 0 rows affected (0.00 sec)

    mysql> GRANT ALL PRIVILEGES on *.* TO santhosh@’%’ identified by ‘yourpwd’
    -> ;
    Query OK, 0 rows affected (0.00 sec)

    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

  47. Ricardo Cruz

    ** Okay, guys, here is how to do it:

    sudo apt-get install mysql-server

    (it should ask a password for mysql user ‘root’)

    sudo start mysql
    mysql -u root -p

    within the mysql shell:

    create user your_username identified by ‘your_pwd’;
    GRANT ALL PRIVILEGES on *.* TO your_username@’%’ identified by ‘your_pwd’;
    flush privileges;

    (you may have to add yourself to the ‘mysql’ group in the Users & Groups admin utility.)

    mysql -u your_username -p
    create database db;

    ** Now, whenever you want to use it:

    sudo start mysql;
    mysql -u your_username -p db;

    create table … ;
    select * from table … ;

  48. akhil balan

    mysql -u root -p

    use this command…
    u’ll be ased a password which woul have been set by you during the installation.
    use tht password…

    :)

  49. superuser

    This is what I have done on my ubuntu 10. From the Terminal

    sudo apt-get install mysql-server

    type your password

    the installation will process, a windows will popup asks to input root password, input whatever password you want. Installation finished

    Same in terminal, type mysql -u root -p
    Enter password: input the password that you have set when you install mysql.

    Finish, you are in mysql>

    I have tested by creating a database, there is no problem so far. For those who complained that the guide does not work, I think you should use your brain seriously, and be patience!

    Thank you for the guide, it works great!

  50. varsha

    can u send me apt-get install mysql-server 5.0 & apt-get install mysql-client 5.0

  51. LewisH

    Quote from: akhil balan

    mysql -u root -p

    use this command…
    u’ll be ased a password which woul have been set by you during the installation.
    use tht password…

    I do exactly this however it does not ask me to provide a password? I’ve even had to –purge mysql-server. And still had no sucess.
    Humpf lol

  52. Simon Yee

    Hi,
    My SQL cant start even with this instruction.
    Help me
    Please email me the message below turned up
    simonyee@ubuntu:~$ sudo /etc/init.d/mysql start
    Rather than invoking init scripts through /etc/init.d, use the service(8)
    utility, e.g. service mysql start

    Since the script you are attempting to invoke has been converted to an
    Upstart job, you may also use the start(8) utility, e.g. start mysql
    simonyee@ubuntu:~$ service mysql start
    start: Rejected send message, 1 matched rules; type=”method_call”, sender=”:1.62″ (uid=1000 pid=10416 comm=”start) interface=”com.ubuntu.Upstart0_6.Job” member=”Start” error name=”(unset)” requested_reply=0 destination=”com.ubuntu.Upstart” (uid=0 pid=1 comm=”/sbin/init”))

    Thanks
    Simon Yee

  53. khalid-k

    Getting started with MySQL is really easy. First you want to install the mysql server. Then you can start the server with this command:

    Code:

    sudo /etc/init.d/mysql start

    Then, because intially the root user has no password, we want to set the password like this:

    Code:

    mysqladmin -u root password myPassword

    You can now login to the mysql server with this:

    Code:

    mysql -u root -p

    You’ll need to type in the password that you entered earlier.

    Every new MySQL install has 2 databases: mysql and test. Do NOT screw up your mysql database because here is where all the permission and user info is. The test DB is for you to play around with. As was mentioned earlier the MySQL documentation is excellent. That’s the main reason I prefer it over the other 2 mentioned above (maybe their docs are better nowadays.) You’ll probably want to set up a new user next. The MySQL docs can help you there.

    You mentioned that you’re familiar with SQL, so you should be able to play around now.

  54. hassan

    hi,
    this tutorial helped me a lot……thank u.

  55. pramod

    Those who are getting this type of error “”mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘honey’@’localhost’ (using password: NO)’Enter your email here””
    enter musql -u toot -p
    and mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘yourpassword’);
    it will work fine

  56. Joe

    mysql is fine but not with this piece of shit Ubuntu 10.04 upstart

    Ubuntu 10.04 is a heap of shit IMO comparing to Ubuntu 8.04.

    Too much compromising in terms of nice animated splash screen control and fast startup. Nothing wrong with that approach, however Ubuntu reinventing the whole fucking wheel and they make it as one way ticket.

    Why the fuck, plymouth is so much integrated deep into the dependency. As far as I can see this is a splash screen

    Why the fuck that you cannot revert back to nice, simple, sequential init.d task.

    Ubuntu 10.04 push users with no choice, they think they know the best and u live with their decisions

  57. Frank Duffey

    rror: ‘Access denied for user ‘frankduffey’@’localhost’ (using password: NO)’

  58. Frank Duffey

    Access denied for user ‘toot’@’localhost’ (using password: YES)
    way too much BS

  59. farid

    to create database mysql, if password required :

    # mysql -u root -p

    and enter the password, password in the setting when u perform the instalation mysql server.

  60. sonu

    not able to my sql on ubuntu

  61. sam

    Hi,

    Use this for logging to mysql
    mysql –user=root –password=
    create database
    connect

  62. abhishek

    Since the script you are attempting to invoke has been converted to an
    Upstart job, you may also use the restart(8) utility, e.g. restart acpid
    acpid start/running, process 14114
    package libqtgui4 exist
    QT_VERSION = 4
    cd: 156: can’t cd to /usr/local/bin/ztemtApp/zteusbserial/2.6.32
    dpkg: error processing crossplatformui (–configure):
    subprocess installed post-installation script returned error exit status 2
    Errors were encountered while processing:
    crossplatformui
    E: Sub-process /usr/bin/dpkg returned an error code (1)

    hey E is the drive where i hav given space for ubuntu ….
    while installing my sql … i got the above mentionede error
    plz help me out

Enter Your Email Here to Get Access for Free:

Go check your email!