MySQL installation in Debian Etch

After I setup a web application server, I would like to use a database for storing my data. MySQL is a free open source software that I am familiar with. For flexibility, I choose to install the binary non-rpm tar.gz version.

1) I download MySQL binary non-rpm tar.gz version for my AMD ET64T machine. The file is mysql-5.0.45-linux-x86_64-glibc23.tar.gz.

2) For a good practice, I verify the downloaded file using md5sum that is already installed in Debian Etch system. So, I issue the command.

>md5sum -b mysql-5.0.45-linux-x86_64-glibc23.tar.gz

Then, I compare the result with what on the MySQL download web site for this particular version.

3) If everything is ok, I unzip the file and move it to its installation directory such as /opt. Well, first of all, I have to become root.

>tar -zxvf mysql-5.0.45-*.tar.gz

>su

>mv mysql-5.0.45*glibc23 /opt/

4) Then, I change my working directory to /opt/mysql-5.0.45*glibc23

>cd /opt/mysql-5.0.45*glibc23

5) I open “INSTALL-BINARY” file and follow the installation instructions in this file. However, since I want to put the mysql data directory in the /home directory because of space availability reason, I need to edit MySQL configuration file and put the config file in /etc directory (global configuration). Because I plan to use MySQL database for my web application, I use my-medium.cnf file.

So, I copy my-medium.cnf in the $MYSQL_HOME/support-files directory to /etc directory

>pwd

/opt/mysql-5.0.45-linux-x86_64-glibc23

>cd support-files

>cp my-medium.cnf /etc/my.cnf (updated on Feb 22, 2010)

Then, I edit my.cnf file and put the following text under [mysqld] directive to tell MySQL server where the data directory is.

>cd /etc

>vi my.cnf

Look for [mysqld] and add the following text line.

————————————————————————

datadir=/home/mysql_data

————————————————————————

6) Now, I get back to the $MYSQL_HOME directory or /opt/mysql-5.0.45-linux-x86_64-glibc23

>cd /opt/mysql-5.0-45*

7) I begin to follow the instructions in the “INSTALL-BINARY” file as follows.

- Add a new group named “mysql”.

>groupadd mysql

- Add a new user “mysql” to “mysql” group.

>useradd -g mysql mysql

- Make a symbolic link from the $MYSQL_HOME to “mysql” link. So, this will make our life easier to refer to $MYSQL_HOME by using only /opt/mysql rather than using its full name “/opt/mysql-5.0.45-linux-x86_64-glibc23″

>cd ..

>ln -s /opt/mysql-5.0.45-linux-x86_64-glibc23 mysql

- Then, I get back to inside the $MYSQL_HOME

>pwd

/opt

>cd mysql

- I change owner of all files and directories (-R) inside $MYSQL_HOME to mysql.

>chown -R mysql .

- I change group owner of all files and directories (-R) inside &MYSQL_HOME to mysql group.

>chgrp -R mysql .

- Since I want to put MySQL data directory in /home directory and I already specify it as “mysql_data” in /etc/my.cnf file, I move the data directory in $MYSQL_HOME to /home directory and change its name to “mysql_data”.

>mv data /home/mysql_data

- Then, I am ready to install database in MySQL server.

> pwd

/opt/mysql-5.0.45-linux-x86_64-glibc23

>scripts/mysql_install_db –user=mysql

For security reasons, everything inside $MYSQL_HOME should be owned by root except the data directory. Therefore, I change owner of all files and directories inside $MYSQL_HOME to root.

>chown -R root .

Since the /home/mysql_data is already owned by ‘mysql’ user and group, I do not need to do anything else.

8) As root, I start MySQL server as follows.

>bin/mysqld_safe –user=mysql &

Press Enter to get back to the command prompt or open a new terminal.

9) I open a new terminal. As a normal user, I enter the following command to activate MySQL client.

>cd /opt/mysql

>bin/mysql -uroot

10) I issues some commands to test MySQL server and client installations.

mysql>show databases;

mysql>select test;

mysql>show tables;

11) I quit MySQL client

mysql>quit

12) I stop MySQL server. As root.

>bin/mysqladmin shutdown

That’s all for MySQL installation in Debian Etch. Next, I will install connector/j for using MySQL in Java programs.

Any comment or suggestion is very welcomed.

[Update: October 22, 2007]  To secure MySQL database, I do the following steps.

1) I assign root’s password

- Start MySQL server

>cd $MYSQL_HOME

>bin/mysqld_safe &

- Start MySQL client

>bin/mysql -uroot

- Assign root password

mysql>SET PASSWORD FOR root@localhost=PASSWORD(‘new_password’);

2) Then, I remove the ‘test’ database. Note that there are existing databases after a fresh MySQL installation, which are ‘information_schema’, ‘mysql’, and ‘test’.

mysql>drop database test;

3) I delete records from the ‘db’ table in the ‘mysql’ database.

mysql>use mysql;

mysql>delete from db;

4) I remove all users except root from the ‘user’ table in the ‘mysql’ database.

mysql>delete from user where not (host=”localhost” and user=”root”);

mysql>flush privileges;

5) I quit MySQL client and shutdown MySQL server.

mysql>quit

>bin/mysqladmin -uroot -p<new_password> shutdown.

Note that we need to supply username and password for shutting down MySQL server now.

6) I try to restart MySQL server and client again

>bin/mysqld_safe &

>bin/mysql -uroot -p<new_password>

Note that the passwords for shutting down MySQL server and connect to MySQL client are the same one.

About these ads
This entry was posted in database, Linux. Bookmark the permalink.

7 Responses to MySQL installation in Debian Etch

  1. Miksuh says:

    I really don’t understand why you installed MySQL from tar.gz -package. MySQL 5.0.32 is in the official Debian Etch repository as a Debian-package. MySQL in the repository is well tested and it’s supported by the Debian so you will automatically get security updates. There really is no reason to install MySQL from tar.gz -package and if you do so you will not get any updates automatically. In general it is a bad idea to install something from out side of package management system if Debian package is available.

    You can install MySQL this way:

    # apt-get install mysql-server

    You most likely want to install MySQL tools too:

    # apt-get install mysql-client
    # apt-get install mysql-admin
    # apt-get install mysql-navigator
    # apt-get install mysql-query-browser

    If you need PHP5 MySQL-module, here is how you can install it:

    # apt-get install php5-mysql

    There is lots of other MySQL related packages in the Etch repository too. Just search for the mysql in the repository using eg. Synaptic.

  2. mrtextminer says:

    Miksuh and S0enke, thank you very much for your suggestions and comments. It’s just my personal preference to install MySQL using binary tar.gz file. So, I can control and organize my system on where I want to install MySQL and other software packages that are not in Debian repository. I usually try to install any software package using tar.gz file from the developer web site as possible rather than using Debian synaptic package manager unless there are dependency problems in Debian Etch. Moreover, I want to keep my system as stable as possible. So, I avoid using Synaptic to install packages in Debian Etch that are supported in Lenny or sid.

  3. s0enke says:

    With apt-pinning you can choose which packages are installed from stable and which not. I don’t understand why people throw away the comfort of having all in their package manager. If you want to have bleeding-edge up-to-date packages, use sid, new versions go into it with a minimal delay from upstream releases. The java connector is also available as debian package so your howto can be shrinked to this line:

    aptitude install -t unstable mysql-server mysql-connector-java

    You’ll get updates for these packages and so on. So why waste your time with tarballs. I could somehow understand it if you want to compile it by your own, but as you’ve chosen the binary tarball there is absolutely no reason for not using the debian packages.

    Btw: “unstable” does not mean it’s unstable. It is from a debian stable release’s view, ahm, unstable.

  4. Geez says:

    The reason I compile both PHP and MySQL myself is because of flexibility.

    For example; the way ‘Views’ work (in the engine) in MySQL 5.0.32 and in 5.0.51 seem very different (gives me huge performance differences).

    However I cannot simply upgrade to 5.0.51 (or 5.0.45) with apt-get unless I want loads of unstable packages installed.

    In my experience I’ve had less problems compiling MySQL and PHP myself then using apt-get.

  5. mpi says:

    i have Debian etch 32 bit, and the Mysql Distribution 5.0.32 of Debian ist 4 times slower than the self-compiled one.

    Reason is that 5.0.32 is compiled in i486 architecture. i486 architecture doesn’t use the whole potential of an i686 compatible CPU.

    best regards

  6. HerrS says:

    There is a little mistake in


    >cp my-medium.cnf /opt/my.cnf

    Then, I edit my.cnf file and put the following text under [mysqld] directive to tell MySQL server where the data directory is.

    It must be as followes:
    >cp my-medium.cnf /etc/my.cnf

    Greetings
    HerrS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s