Debian Admin - Your way to Debian World

September 11, 2006

Mysql Database Server Installation and Configuration in Ubuntu

by @ 3:31 pm. Filed under Database

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

Tags: , ,

You may also be interested in...

6 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.

Leave a Reply

Subscribe RSS Feed

subscribe to the Debian Admin RSS feed

Internal links:

Sponsors:



Categories:

Support Debian Admin

Amount $:
Website(Optional):

Sponsors:

Archives:

Related Links:


Favourite Sites:

Wordpress Collection
Windows Reference
Ubuntu Geek
DebianHelp
All About Debian Tutorials
Power Electrical
Check Your IP Here
Debian,Ubuntu News
DebCentral
Tuxmachines
Capnkirby
Libervis
Nuxifield
Linux Horizon
Linux Appfinder
Debuntu
GNU/Linux For Everyone
Free Penguin
DebianAdmin is not related to the Debian Project.
This site is copyright © 2006,2007 Debian Admin
All Trademarks are the property of their respective owners.
The contents of this website may not be mirrored or archived without the express written permission of DebianAdmin Site Owner.

DISCLAIMER: All the information, troubleshooting methods, utilities offered in this website is provided AS-IS, without any warranties. Though I strive for perfection, and always test the validity and effectiveness of the troubleshooting content in various systems, I assume no responsibility for your use of these Fixes, Utilities and other troubleshooting advice. The author will not be liable for any special, incidental, consequential or indirect damages due to loss of data or any other reason. All use is completely at your own risk. Changes to the existing content and new additions are made to this website periodically, without notification.
Rodney's Kontera DynamiContext Plugin plugged in.