Debian Admin

Debian/Ubuntu Linux System Administration Tutorials,Howtos,Tips

  • RSS Subscribe

    subscribe to the Debian Admin RSS feed
  • Sponsors



  • Categories

  • Sponsors

  • Support DebianAdmin

    Amount $:
    Website(Optional):


  • Meta

  • Archives



Mysql Database Server Installation and Configuration in Ubuntu

Posted by Admin on September 11th, 2006

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

MySQL is a widely used and fast SQL database server. It is a client/server implementation that consists of a server daemon (mysqld) and many different client programs/libraries.

Installing Mysql database in Ubuntu

#apt-get install mysql-server mysql-client libmysqlclient12-dev

MySQL initially only allows connections from the localhost (127.0.0.1). We’ll need to remove that restriction if you wish to make it accessible to everyone on the internet. Open the file /etc/mysql/my.cnf

#vi /etc/mysql/my.cnf

Find the line bind-address = 127.0.0.1 and comment it out

#bind-address = 127.0.0.1

You can check your configuration using the following command

#netstat -tap

Output Looks like below

tcp 0 0 *:mysql *:* LISTEN 4997/mysqld

MySQL comes with no root password as default. This is a huge security risk. You’ll need to set one. So that the local computer gets root access as well, you’ll need to set a password for that too. The local-machine-name is the name of the computer you’re working on. For more information see here

#mysqladmin -u root password your-new-password

#mysqladmin -h root@local-machine-name -u root -p password your-new-password

#/etc/init.d/mysql restart

If you are looking how to create database,tables and other things check here

If you are looking for webinterface administration or GUI tools for your mysql database check here

  • Share/Bookmark

16 Responses to “Mysql Database Server Installation and Configuration in Ubuntu”

  1. Lois Says:

    Hi!
    I have installed mysql server on my Ubuntu Desktop; and works fine, but I want to change de mysql datadir. Do yo know how can I change that? If I edit my.conf the line datadir for my directori, mysql never restarts.
    The new datadir is with the same permissions, and content.

    Any ideas? Wy in apache is easy to change but in mysql not?

  2. Admin Says:

    Hi Lois,

    Here is the procedure how to change Mysql default data directory

    By default, MySQL’s datadir is placed in the /var/lib/mysql directory.

    Create the directory that will be new datadir (ex:-/home/db)

    chown the directory to the mysql:mysql user

    sudo chown -R mysql:mysql /home/db/*

    You need to stop the mysql server using the following command

    sudo /etc/init.d/mysql stop

    Now you need to edit the /etc/mysql/my.cnf file

    sudo vi /etc/mysql/my.cnf

    and look for “datadir = /var/lib/mysql” this si where mysql database default data directory here you need to change this one to your new directory

    datadir = /home/db

    copy the files from the old datadir to the new location. However, make sure that the files named
    ib_arch_log_0000000000, ib_logfile0 etc. are not copied to the newer location.

    Make sure that the files and directories are owned by mysql user

    Make changes in the my.cnf to point the new datadir.

    Restart the MySQL database

    sudo /etc/init.d/mysql start

    hope this helps

  3. Lois Says:

    Yeah!!! you’re my hero! my problem was the direcotri privilegies in the new datadir; but that’s it with the chown -R mysql:mysql.
    Do it after copying the files.

    Thanks for all!

  4. Tanya Says:

    why can not I use
    sudo /etc/mysql/my.cnf

    and I have /etc/my.cnf
    so I used
    sudo /etc/my.cnf
    it said command not found

    I did not find “datadir = /var/lib/mysql” in the file my.cnf either.

    I want to change the directory of the database, because not enough disk space left.
    anybody knows , Please help me, Thanks a lot.

  5. Admin Says:

    you need to make sure you have vi editor installed in your machine otherwise install vi using the following command

    #apt-get install vim

    Now you need to edit the file using the following command

    sudo vi /etc/mysql/my.cnf

    If you install mysql in debian or ubuntu from packages you will find the above file without any problem.

    Please give us which operating system you are running and how did you installed mysql server in your machine.

  6. nickrud Says:

    Since apparmor is now standard in ubuntu (at least since hardy, which is the release I’m working with now) you will also have to make a change to /etc/apparmor/apparmor.d/usr.sbin.mysqld as well in order to change the datadir. I needed to add the lines

    /home/mysql/ r,
    /home/mysql/** rwk,

    to enable the correct access permissions to the new data directory.

  7. Chris Chua Says:

    Thank you so so so so soooo much, nickrud. Your comment saved me. I’ve been trying this for the past 3 hours and it’s 5am (over here) now. I wonder where to look for such gotchas like that… How would a newbie like me know about apparmor? It’s even a standard and I had no clue it existed…

  8. HaC|away Says:

    Another thing you should not forget is to restart /etc/init.d/apparmor after changing the /etc/apparmor.d/usr.sbin.mysqld file. I wondered why it did not work ;)

  9. sarang Says:

    Hey

    One of our application developer requested to change the ownership of my.cnf file from root to mysql user and mysql group.

    I was thinking about it could not think of any reason why I cannot do this.

    Would this be ok or is there a reason why we shoulc have /etc/my.cnf owned by root.

    Let me know.
    Thanks,
    SArang

  10. sergey Says:

    Thanks! It works!!!

  11. Somnuk Says:

    Greate nickrud, you really help me.

  12. Anton Says:

    Thanx!!! It almost worked… BUT I have a problem: after I configured directory privileges and apparmor and MYSQL conf file – everything seems to work fine. BUT the problem is – I can not create NEW DATABASES – it tells me error#13. Does anybody know something about this problem?

    Thanks in advance! :)

  13. Rabindra Says:

    thanks for the solution

  14. Grant Says:

    Hello

    I am getting some errors that I cannot understand/resolve:

    I am trying to reset the root password for mysql and this happens

    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@'localhost’ (using password: NO)’

    How do I fix this.

  15. Simon Taylor Says:

    Hi,

    I get the same error:
    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’

    Don’t get it!

    Cheers

  16. Grant Says:

    Hello,

    How are you logging into mysql. Is it something like this?

    $ mysql -u root -p

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>