31 January 2007

Now the ugly-one : MySql

Let's start by installing one MySql dependency :
yum install perl-DBI
And now go to MySql site and copy the url of the file to download, from "Red Hat Enterprise Linux 4 RPM (x86) downloads" in our case. We need two files :

  • one for the server : MySQL-server-standard-5.0.27-0.rhel3.i386.rpm
  • and another for the client : MySQL-client-standard-5.0.27-0.rhel3.i386.rpm

Let's do some wget (in the /opt folder, just to be consistent) :

wget http://mysql.org/get/Downloads/MySQL-5.0/MySQL-server-standard-5.0.27-0.rhel3.i386.rpm/from/http://mysql.mirror.redwire.net/
wget http://mysql.org/get/Downloads/MySQL-5.0/MySQL-client-standard-5.0.27-0.rhel3.i386.rpm/from/http://mysql.mirror.redwire.net/
Just don't rush to install anything. It won't work (the server, at least). It's because of the dreaded SELinux. Don't ask my what is it. Ask Google ;-) But it prevents some services to run as expected.
We need to circumvent this. It is not easy, but thanks to this post, it's doable :

  • install SELinux policy sources
    yum install selinux-policy-targeted-sources.noarch
  • now type
    setenforce 0
    go to /etc/selinux/targeted/src/policy/domains/program (added by the previous install) and edit the file mysqld.te
  • find the lines (!! all 3)
    # because Fedora has the sock_file in the database directory
    file_type_auto_trans(mysqld_t, mysqld_db_t, mysqld_var_run_t, sock_file)
    ')
  • just below add the following
    #
    allow mysqld_t var_lib_t:dir { write add_name remove_name };
    allow mysqld_t var_lib_t:file { append create lock read write getattr unlink };
    allow mysqld_t var_lib_t:sock_file { create getattr unlink };
    #
  • Go back to /etc/selinux/targeted/src/policy and run :
    make load
    setenforce 1
  • Ready ! I mean you are ready to continue with the MySql install

Now go back to /opt. And do :

rpm -ivh MySQL-*

And done with the tricky part !

Now let's set a password for the root mysql user :

mysqladmin -u root password 'root'

Testing a little bit :

mysql -proot

You can perform an \s to see the server status. You exit from there with \q

Are we ready ? Nooo .... We must access our server from outside (from our Windows machine, for example, to work on the databases).

Out of the box mysql doesn't allow this. But we can type :

mysql -u root -proot

and then

mysql> grant all privileges on *.* to your-user@'%' identified by your-password with grant option;

Now you can carelessly fire you MySql Administrator or Query Browser and connect using the linux box's IP and the user you just set (your-user with the password your-password).

No comments:

Post a Comment