Bug #69076 RPM install not using cnf data dir
Submitted: 26 Apr 2013 5:33 Modified: 26 Apr 2013 20:59
Reporter: Sajjad Tariq Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Installing Severity:S2 (Serious)
Version:5.6.11 OS:Linux (CentOS release 6.3 (Final))
Assigned to: CPU Architecture:Any
Tags: cnf, data dir, install, mysql 5.6

[26 Apr 2013 5:33] Sajjad Tariq
Description:
When installing MySQL server, it ignores the data dir listed in cnf and installs under /var/lib/mysql

How to repeat:
-Set a custom data in cnf
-Install server by RPM
-Server is installed under /var/lib/mysql

[root@]# cat /etc/my.cnf | grep datadir
datadir         = /db01/mysql

[root@]# ls -alh /var/lib/mysql/
total 20K
drwx------  5 mysql mysql 4.0K Apr 26 00:14 .
drwxr-xr-x 29 root  root  4.0K Apr 26 00:13 ..
drwx------  2 mysql mysql 4.0K Apr 26 00:14 mysql
drwx------  2 mysql mysql 4.0K Apr 26 00:14 performance_schema
drwx------  2 mysql mysql 4.0K Apr 26 00:13 test

[root@]# ls -alh /db01/mysql/
total 24K
drwxr-xr-x 4 mysql mysql 4.0K Apr 26 00:14 .
drwxr-xr-x 4 mysql mysql 4.0K Apr 26 00:13 ..
drwx--x--x 2 mysql mysql 4.0K Apr 26 00:13 mysql
-rw-r--r-- 1 root  root   111 Apr 26 00:14 RPM_UPGRADE_HISTORY
-rw-r--r-- 1 mysql mysql  111 Apr 26 00:14 RPM_UPGRADE_MARKER-LAST
drwxr-xr-x 2 mysql mysql 4.0K Apr 26 00:13 test

Suggested fix:
Have RPM use data dir from cnf for db_install.
[26 Apr 2013 8:13] MySQL Verification Team
Hello Sajjad,

Thank you for the report.
I think this is not a bug, because as per the official manual installations created from our Linux RPM distributions result in files under the system directories shown as shown below: 

Directory	Contents of Directory
/usr/bin	Client programs and scripts
/usr/sbin	The mysqld server
/var/lib/mysql	Log files, databases
/usr/share/info	Manual in Info format
/usr/share/man	Unix manual pages
/usr/include/mysql	Include (header) files
/usr/lib/mysql	Libraries
/usr/share/mysql	Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation
/usr/share/sql-bench	Benchmarks

See, http://dev.mysql.com/doc/refman/5.6/en/linux-installation-rpm.html#mysql-installation-layo...

Also, package MySQL-server is not relocatable

[root@cluster-repo setups]# rpm -ivh --prefix=/data/ushastry/setups --nodeps --noscripts MySQL-server-5.6.11-1.el6.x86_64.rpm
error: package MySQL-server is not relocatable

Workaround(s):

(1)
You can install the rpm's with the parameter  --noscripts option, which makes sure the post-installation scripts are not run.. later on, you need to manually run mysql_install_db, after making sure directories are created. Make sure the permission of the directories are correct.. something like

/bin/mysql_install_db --defaults-file=/path/to/my.cnf \
--basedir=/var/lib/mysql \
--datadir=/db01/mysql

(2) Try tar binaries and customize your environment
[26 Apr 2013 20:59] Sajjad Tariq
Umesh,

I will try to perform the work around. But wanted to point out, this is different from 5.5. Hence, similar functionality should be carried forward in 5.6.

Thank you,

Sajjad
[25 Apr 2014 10:00] Andreas Eiken
I have the same problem after changing from 5.5 to 5.6.
The problem is in the preinstall script of the rpm, so the following steps helps making an installation as wanted:

1. first install mysql without preinstall script:

rpm -i --nopost  MySQL-server-5.6.15-1.el6.x86_64.rpm

2. extract the preinstall script from the package and redirect to a file
rpm -q --scripts MySQL-server-5.6.15-1.el6.x86_64 | awk 'BEGIN{found=0;}{if ($2 == "scriptlet"){if ($1 == "postinstall")found=1;else found=0;}else if (found == 1)print $0;}' > preinstall.sh

3. open the file, search for mysqlinstall_db call 

/usr/bin/mysql_install_db --rpm --user=mysql --random-passwords

4. change to the following and save and leave the file:
/usr/bin/mysql_install_db --rpm --user=mysql --random-passwords --datadir=$mysql_datadir

5. add execution rights to the script:
chmod +x preinstall.sh

6. execute the preinstall script
./preinstall.sh

Now everything should be correctly installed.
Sure, change MySQL-server-5.6.15-1.el6.x86_64 to your used package name.

Hope, this could be changed in the package by oracle!
[25 Apr 2014 10:02] Andreas Eiken
Sorry,
I've talked about preinstall script but the example shows the postinstall script.
At least the postinstall script is correct!