Bug #1279 Can't find file: './mysql/host.frm' (errno: 13)
Submitted: 14 Sep 2003 23:12 Modified: 18 Sep 2003 13:38
Reporter: Ralf Hauser Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Installing Severity:S2 (Serious)
Version:4.0.15 binary OS:Linux (linux)
Assigned to: CPU Architecture:Any

[14 Sep 2003 23:12] Ralf Hauser
Description:
After running "./scripts/mysql_install_db" under root, when trying to start mysqld, I still get

[root@cake mysql]# ./bin/mysqld --user=mysql &
[1] 32573
[root@cake curr]# 030915  2:04:01  InnoDB: Started
030915  2:04:01  Fatal error: Can't open privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
030915  2:04:01  Aborting

030915  2:04:01  InnoDB: Starting shutdown...
030915  2:04:03  InnoDB: Shutdown completed
030915  2:04:03  ./bin/mysqld: Shutdown Complete

How to repeat:
try to run it again

Suggested fix:
on a different installation, I noticed, that there is a mysql directory containing host.frm etc.
I guess this was created with mysql_install_db

Suggestion: have "mysql_install_db" test whether its "deliverables" are really created at the end and otherwise have it print some help lines how to fix that.

---
I don't know yet what those lines would be since I haven't fixed it yet!
[14 Sep 2003 23:16] Ralf Hauser
P.S.: I am aware of http://www.mysql.com/documentation/mysql/bychapter/manual_Installing.html#Post-installation, but this didn't really help.
[15 Sep 2003 1:23] Guilhem Bichot
Can't find file: './mysql/host.frm' (errno: 13)

[guilhem@gbichot2 guilhem]$ perror 13
Error code  13:  Permission denied

Check that the user which runs the MySQL server (mysqld) has enough privileges on the 'mysql' directory and on its content.
[15 Sep 2003 1:41] Ralf Hauser
Thanks for the hint.
Unfortunately, the problem appears to worse:

there is no mysql/mysql directory containing the host.frm and alikes.

And creating it by hand doesn't really help...

Which command creates those files?
[15 Sep 2003 2:10] Guilhem Bichot
It's definitely a permission problem (error 13).
Re-run mysql_install_db, check the messages mysql_install_db prints, checks where the files are created (if they are not created, there will be error messages in mysql_install_db)... This is very probably not a bug so I'm closing it; if you need more assistance, you may get some more with this list: mysql@lists.mysql.com.
[15 Sep 2003 2:16] Ralf Hauser
Do you see an error message there?

<<[root@cake mysql]# ./scripts/mysql_install_db
Installing all prepared tables
030915  5:16:32  ./bin/mysqld: Shutdown Complete

To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
This is done with:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h cake.pushtotest.com password 'new-password'
See the manual for more instructions.

NOTE:  If you are upgrading from a MySQL <= 3.22.10 you should run
the ./bin/mysql_fix_privilege_tables. Otherwise you will not be
able to use the new GRANT command!

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests

Please report any problems with the ./bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at https://order.mysql.com

[root@cake mysql]#>>
the files are not created and I cannot start mysqld?
[15 Sep 2003 13:08] Guilhem Bichot
you are running commands from the MySQL source directory, but this is not where the 'mysql' database is created. It is created in a directory called the MySQL data directory, which is (as you build from source), by default /usr/local/mysql.
From our manual:
# Configure the release and compile everything:

shell> ./configure --prefix=/usr/local/mysql
shell> make

When you run configure, you might want to specify some options. Run ./configure --help for a list of options. section 2.3.3 Typical configure Options, discusses some of the more useful options. If configure fails, and you are going to send mail to mysql@lists.mysql.com to ask for assistance, please include any lines from `config.log' that you think can help solve the problem. Also include the last couple of lines of output from configure if configure aborts. Post the bug report using the mysqlbug script. See section 1.7.1.3 How to Report Bugs or Problems. If the compile fails, see section 2.3.5 Problems Compiling MySQL?, for help with a number of common problems.
# Install everything:

shell> make install
You might need to run this command as root.
# Create the MySQL grant tables (necessary only if you haven't installed MySQL before):

shell> scripts/mysql_install_db

Note that MySQL versions older than Version 3.22.10 started the MySQL server when you run mysql_install_db. This is no longer true.
# Change ownership of binaries to root and ownership of the data directory to the user that you will run mysqld as:

shell> chown -R root  /usr/local/mysql
shell> chown -R mysql /usr/local/mysql/var
shell> chgrp -R mysql /usr/local/mysql
[15 Sep 2003 21:52] Ralf Hauser
I am confused:
- I downloaded a binary version and now you are telling me I only can get it running if I use "make install", i.e. I have to go back and get the source and compile everything?
- I did execute the "./scripts/mysql_install_db" as you said in "/usr/local/mysql", but nothing happened. Even if I do "chmod 777 /usr/local/mysql":
rwxrwxrwx   14 root     mysql        1024 Sep 15 04:42 .

and again I DON'T AN ERROR TEXT WHATSOEVER in the mysql_install_db output.

Admitted, one peculiarity is that my /usr/local/mysql is a symlink to /opt/mysql/curr/ which in turn is a symlink to /opt/mysql/mysql-standard-4.0.15-pc-linux-i686

OK, then I went an removed the /user/local/mysql symlink and did:
 1021  mkdir mysql
 1022  chmod 777 mysql/
 1023  cd mysql/
 1024  /opt/mysql/curr/scripts/mysql_install_db
Didn't find ./bin/mysqld
You should do a 'make install' before executing this script
 1025  ln -s /opt/mysql/curr/bin
 1026  /opt/mysql/curr/scripts/mysql_install_db
Installing all prepared tables
030916  0:49:16  Can't find messagefile '/usr/local/mysql/share/mysql/english/er
rmsg.sys'
030916  0:49:16  Aborting

Installation of grant tables failed!
...
 1027  ln -s /opt/mysql/curr/share
 1028  /opt/mysql/curr/scripts/mysql_install_db

And now I am back to "square 1": No more error messages are shown, but host.frm still hasn't been installed
[18 Sep 2003 7:20] Sergei Golubchik
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem is not the result of a bug.
For a list of more appropriate places to ask for help using MySQL
products, please visit http://www.mysql.com/support/

Thank you for your interest in MySQL.
[18 Sep 2003 7:45] Ralf Hauser
Is there an official MySQL AB definition of a bug?

For me, having an installation script (mysql_install_db) that fails without giving a warning, i.e. it apparently doesn't create what it is built for is a bug.
[18 Sep 2003 13:38] Sergei Golubchik
as guilhem said several times, it's permission problem!
The script did succeed, but files that were created are not accessible for mysqld, as you run it with different settings (notably, with --user=mysql, while table files, the way you run the script, were created to be readable by root 

Check "Installing binary" section of the manual
http://www.mysql.com/documentation/mysql/bychapter/manual_Installing.html#Installing_binary
[18 Sep 2003 23:33] Ralf Hauser
o.k., you are right. During my chown mysql excercise, I did
cd /var/lib/mysql
chown mysql mysql/. 
  (but I skipped)
chown mysql mysql/*

apologies for this oversight, it works now!

In order to avoid similar problems in the future and in light of mysqld refusing to start as root (unless I read the "Security" section of the manual).

Suggestion:
===========
After successful installation of the *.frm and alike, have
/opt/mysql/curr/scripts/mysql_install_db check who owns those and what rights they have.
If a problem with root ownership and non-755 permission is found, warn the user with something like the below.

<<Warning:
=======
You will only be able to run mysqld with root privileges. This is deprecated!

For example, the below file will be a problem
-rw-rw---- 1 root root  9064 Sep 15 01:37 /var/lib/mysql/mysql/host.frm

We urge you to make the directory /var/lib/mysql/mysql and all the files in it readable to the user who will run the mysqld in the end (recommendation:
create a user "mysql" as per http://www.mysql.com/documentation/mysql/bychapter/manual_Installing.html#THE_SECTION_ABOUT_THE_MYSQL_USER)
The commands to do this are for example:
  cd /var/lib/mysql
  chown mysql mysql/. 
  chown mysql mysql/*
>>
[24 Jan 2005 20:02] Michel Donais
I would like to add up a small "bug/comment" on this section, even if it's old. That way, i'm not crating a new "bug"

I have successfully installed the latest version (4.1.9) on many computers from the binary. These are all linux i686 max versions.

The only place where I got this problem was on Red Hat 3.0ES. I don't know why.

my commands are:

decompressing to /usr/local/mysql-whatever-version-number.
ln -s /usr/local/mysql-whatever-version-number /usr/local/mysql
chown -R mysql:mysql mysql-whatever-version-number
ln mysql/support-files/mysqld.server /etc/rc.d/init.d/mysqld
chkconfig --add /etc/rc.d/init.d/mysqld
cd mysql
./configure
/etc/rc.d/init.d/mysqld start

I must've done this for at least a few versions in 4.1.x branch, on at least a dozen servers. And strangely enough, on my ES 3.0, it doesn't work, the folders inside data/ are created by root:root, and not by mysql:mysql, which sounds to me very weird. Again no error message. Took me a few hours to figure out that one ... thanks to that "bug", I got it running correctly by chowning the internal folders.

So now, I add "chown -R mysql:mysql data" to my commands I execute, immediately after ./configure.

I am using the mysql-max-4.1.9-pc-linux-gnu-i686 package.
[26 Oct 2005 22:27] Donny Z
I've stumbled with the same problem. At first mysql running fine, but then this error occurs. Take me a night to figure it out. MySQL said that the file doesn't exists, but actually it does. No problem with the permissions, so I figure it must be the file. Somehow it corrupted. Then I remove the whole /var/lib/mysql/mysql directory, and then do the mysql_install_db. Voala ! Running smooth like before.

Note that mysql_install_db wont work if the /var/lib/mysql/mysql still there.
[30 Oct 2005 1:16] Chad Townsend
I had the exact same problem on initial rpm install.

rm -rf /var/lib/mysql/mysql ; /usr/bin/mysql_install_db

worked like a charm - thanks.
[19 Jan 2006 11:36] Adam Roper
Also worth noting that I had this problem myself when installing MySQL-server 4.1/5.0 on FC4.

The solution:

Disable SELinux, reboot, mysql service starts with no problems at all
[22 Mar 2007 15:58] Sanjay Jaiman
Digest from this thread:  Steps that worked for me - 

1. // install sql mysql-standard-4.0.22-pc-linux-i686 in /usr/local & make a softlink to the new dir
   ln -s /usr/local/mysql-standard-4.0.22-pc-linux-i686 /usr/local/mysql
2. cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
   // edit /etc/my.cnf
   // change all insatnces of "/usr/local/mysql/data/" to /var/lib/mysql/data/"
3. // Put the new mysqld in the /usr/bin dir
   mv /usr/sbin/mysqld /usr/sbin/mysqld.sav
   ln -s /usr/local/mysql/bin/mysqld /usr/sbin/mysqld 
4. //copy the new Create new mysql_install_db script to /usr/sbin
   cd /usr/local/mysql
   cp scripts/mysql_install_db /usr/bin/.
5. // Create new database files
   rm -rf /var/lib/mysql/mysql
   /usr/bin/mysql_install_db
   cp /var/lib/mysql/mysql/* /var/lib/mysql/.
6. // Change access privilidges of the db files
   cd /var/lib/mysql
   chown -R mysql:mysql *
7. // Change access privilidges of other files
   chgrp -R mysql /var/run/mysql
   chgrp -R mysql /var/run/mysqld
   cd /usr/local/mysql
   chown -R mysql:mysql *
   cd /var/lib/mysql
   chown -R mysql:mysql *
8. // Run mysqld in safe mode
   cd /usr/local/mysql/
   bin/mysqld_safe --user=mysql &
[11 Jun 2011 20:38] Saul Uribe
Not sure if this bug has been solved, this is how I did on my box

When I ran mysql_install_db as root, its created the database at /var/lib/mysql but with owner as root, like:

total 21M
-rw-rw---- 1 mysql root  8.8K Jun 11 14:18 betel.err
-rw-rw---- 1 mysql mysql 5.0M Jun 11 14:18 ib_logfile0
-rw-rw---- 1 mysql mysql 5.0M Jun 11 13:23 ib_logfile1
-rw-rw---- 1 mysql mysql  10M Jun 11 13:23 ibdata1
drwx------ 2 root  root  4.0K Jun 11 14:06 mysql/
drwx------ 2 root  root  4.0K Jun 11 14:06 test/

So, what I did was to change the owner of mysql/ and test/ directory with:

chown mysql:mysql -R mysql/
chown mysql:mysql -R test/

and then started the mysqld
Hope this can help you
Enjoy!
[3 Aug 2011 0:02] Cristian Baciu
Hi,

I have this problem in Zend Server 5.1.0 under Mac OS X 10.7 Lion.
It's all about permissions. See Saul Uribe comment. 
You should run

cd /usr/local/zend/mysql/data
sudo chown -R zend:wheel mysql

Regards,
Cristi