I'm trying to understand the reason why I keep experiencing problems while using INTO OUTFILE command.
I always get this erroro:
ERROR 1 (HY000): Can't create/write to file '/var/www/p1.txt' (Errcode: 13)
SELECT password FROM mysql.user WHERE user='root' INTO OUTFILE '/var/www/p1.txt';
Useful details:
web application : DVWA (localhost) (for study purposes)
Server: Apache/2.2.14 (Ubuntu) - PHP/5.3.2
MySQL version 5.1.63
Operating system Linux Backtrack 5r3.
I'm running the command as root. Also, I can freely create folders or files in /var/www/
Errcode 13 I know it means permission denied, but what should I do in order to fix the problem?
Any help will be highly appreciated.
Even if you're logged in as root into MySQL, the file write will be performed as the user running the actual MySQL daemon.
In other words, you should check which user runs mysqld, and give write permission to the directory for that user.
you must alter the permissions for user mysqld. start by running the following command sudo aa-status to check your user status and authorized directories. if you want to change permissions, edit /etc/apparmor.d/usr.sbin.mysqld and insert the directories you want.
you must then restart apparmor sudo /etc/init.d/apparmor restart
chown /var/www to the user trying to write the file, or chmod 777 /var/www
this is probably not a secure way of doing it, you might like to consider putting the file elsewhere
Although this post is quite old, in 2018 this problem is still there. I spent a couple of hours banging my head in this maze.
Server version: 5.7.24 MySQL Community Server (GPL) running on Ubuntu 14.04
To allow MySql to SELECT INTO OUTFILE requires to set MySQL's secure-file-priv option in your configuration.
Append the following 2 lines to /etc/mysql/mysql.conf:
[mysqld]
# allow INTO OUTFILE file and LOAD DATA INFILE to this directory
secure_file_priv=/usr/share/mysql-files
/usr/share/mysql-files is the directory where my files will be stored. I created it doing:
sudo su
cd /usr/share
mkdir mysql-files
chown mysql:mysql mysql-files
chmod a+rw mysql-files
Change /usr/share/mysql-files for whatever you prefer, but avoid to use the /tmp directory!
Why?
Because, at next time you'll be rebooting, the /tmp directory is happily erased including your precious mysql-files sub-directory. The mysql service then chokes and it won't start, leading to wierd errors with cryptics messages.
restart mysql and check:
sudo su
service mysql restart
mysql
mysql> SHOW VARIABLES LIKE "%secure%";
+--------------------------+-------------------------+
| Variable_name | Value |
+--------------------------+-------------------------+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | /usr/share/mysql-files/ |
+--------------------------+-------------------------+
3 rows in set (0.07 sec)
mysql> quit
Bye
You are not done, yet!
There is a troll by the name of apparmor who will ruines your project.
Edit the file /etc/apparmor/local/usr/sbin/mysqld and append the
following 2 lines -- don't forget the ending commas:
/usr/share/mysql-files rw,
/usr/share/mysql-files/** rw,
save it, and reparse:
sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld
That should make it.
On centos the selinux thing is playing not-nice.
$ getenforce
Enforcing
$ setenforce 0
Permissive
Now this is crude, but worked for me (until reboot, then it switches back on).
If this temporary measure works, you need to google for how to configure selinux properly.
Check the user of mysqld with,
ps -aef | grep mysql
mysql 9355 9102 0 Aug24 ? 21:53:25 /usr/libexec/mysqld
Check wiich group mysql belong to with,
groups mysql
mysql : mysql www
Then write the file under path which belong to mysql or have write permission for group www and mysql. For example, test under has write permission to group www.
ll /data/
drwxrwxr-x 2 www www 4096 Dec 9 19:31 test
Then execute mysql mysql -u root -p -e 'use sc_test; select file_path from sc_files INTO OUTFILE "/data/test/paths.txt";'
I was fighting with this enigmatic error for hours, too, tried everything I could find, to no avail, and finally remembered I already had this same problem years before without being able to find a solution back then no matter how long I searched for and tried all these smart counsels.
secure_file_priv was new to me but I didn't try this because I didn't want to rebuild my docker container just to make this work.
Solution
Looking at my docker-compose file I found the solution to this problem: I didn't have a mapping to the target directory, so for the mysql container this directory wasn't existent.
Workaround
Back then I developed a workaround for my cron jobs:
first dump to tmp (to which my container has a mapping)
mv to where it should be in the first place
Well, it works fine, so why bother.
Related
I've been struggling for a couple of days with this now and have been trying to use this thread amongst other google searches to resolve it but can't seem to get it to work.
When I run this SELECT query (Ubuntu Server 15.10 & MySQL 5.6)...
SELECT column1 ,column2
FROM table
INTO OUTFILE '/home/user/mysql_temp/file.csv';
I get this permission error...
ERROR 1 (HY000): Can't create/write to file '/home/mysql_temp/file.csv' (Errcode: 13 - Permission denied)
From my searching, I understand this to be a system permissions issue rather than a MySQL problem but I can't seem to find a solution which fixes it for me.
Checking apparmor shows that mysqld IS in enforce mode...
apparmor module is loaded.
6 profiles are loaded.
6 profiles are in enforce mode.
/sbin/dhclient
/usr/lib/NetworkManager/nm-dhcp-client.action
/usr/lib/NetworkManager/nm-dhcp-helper
/usr/lib/connman/scripts/dhclient-script
/usr/sbin/mysqld
/usr/sbin/tcpdump
0 profiles are in complain mode.
2 processes have profiles defined.
2 processes are in enforce mode.
/sbin/dhclient (676)
/usr/sbin/mysqld (1285)
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.
So I edited /etc/apparmor.d/usr.sbin.mysqld and added the following lines and then restarted apparmor...
/home/user/mysql_temp/ rw,
/home/user/mysql_temp/* rw,
I also changed the owner:group of mysql_temp to mysql and gave it full permissions...
sudo chown mysql:mysql mysql_temp
...
drwxrwxrwx 2 mysql mysql 6 Apr 1 22:02 mysql_temp
After this, I still receive the same error.
Have I missed something? Misunderstood some of the instruction? Would be grateful for advice. Thanks.
What worked for me was accessing the my.ini file. Within that file, look for "Secure File Priv." There should be a file path which is the secure route mySql gives permissions to output the designated file. I hope this helps! For me, the file was under C:/ProgramData/mysql/mysql Server 5.7
Solution Based On; Ubuntu 20.10 with Apparmor active and MySql 8
Solution Summary and Lesson Learned:
Unless you have a damn good reason not to
Leave the default secure-file-priv settings alone,
Give your user(s) FILE privileges in mysql,
And tell apparmor to allow writing to the default directory set up by the mysql installer.
The default configuration set secure-files-priv to /var/lib/mysql-files. Left as it was, I was able to import files by placing them in that directory so long as I gave the user file privileges like so, GRANT FILE ON *.* TO myuser#host;
However, when I tried to write to that directory I got the dreaded Error Code: 1. Can't create/write to file '/var/lib/mysql-files/select_out.csv' (OS errno 13 - Permission denied). I could have solved this very easily by editing /etc/apparmor.d/usr.sbin.mysqld and changing
# Allow data files dir access
/var/lib/mysql-files/ r,
/var/lib/mysql-files/** rwk,
to
# Allow data files dir access
/var/lib/mysql-files/ rw,
/var/lib/mysql-files/** rwk,
But I didn't know about apparmor at the time, and so I fumbled around screwing up more stuff until I found #spcurtis81's post. If that's what happened to you, read on, maybe you can learn something from my journey.
Unfortunately at some point - and god only knows why - I decided to move the secure-file-priv directory to /mysql-files. This created a lot more work for me. If nothing else it taught me a lot, and gave me the opportunity to share.
I had to change the 'secure-files-priv' setting under [mysqld] section in one of .cnf files, but which, there are so damn many. I found it by doing this,
cd /
find . -name "*.cnf" -printf '%p\n' -exec grep "\[mysqld\]" {} \;
and getting
./conf.d/mysqldump.cnf
./conf.d/mysql.cnf
./my.cnf
./debian.cnf
./mysql.conf.d/mysqld.cnf
[mysqld]
./mysql.conf.d/mysql.cnf
./mysql.cnf
so the file above the [mysqld] was the one for me. I found several references to modifying my.cnf but as it didn't already have the section in it, I went with mysqld.cnf. I also reckoned that the mysqld.cnf was for the server daemon as opposed to the user program. It worked, so it aint stupid, but perhaps a more knowledgeable person could explain the hierarchy of .cnf files.
There was no existing secure-files-priv entry for this setting so I found what seemed to be a reasonable location for it and added the following.
# Added 12/13/2020 in an attempt to relocate the secure-file-priv directory
secure-file-priv = /mysql-files
No joy. I found another reference that said that you had to specify a temp directory and so I uncommented this line from the same file.
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
tmpdir = /tmp
Still no joy. Then I found #spcurtis81's post here and learned about the apparmor settings. So in /etc/apparmor.d/usr.sbin.mysqld I changed
# Allow data files dir access
/var/lib/mysql-files/ r,
/var/lib/mysql-files/** rwk,
to
# Allow data files dir access
/mysql-files/ rw,
/mysql-files/** rwk,
AND still no f-ing joy!
The final step that resolved the issue: chmod -R 700 /mysql-files
When I had created the directory I set the owner to mysql and gave it 644 permissions. That seemed reasonable but added an error to my mysql error log: 'Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.'
I don't like security warnings so I changed the permission to 600, never thinking mysql would need executable rights on a data directory. I was wrong. So, there you go.
It's an directory error where you storing the data.
give the permission to the folder where data is store in your case the data store in the "mysql_temp"
use the command "$ chmod 777 mysql_temp"
Don't forget, you have to reload apparmor.
$ sudo service apparmor reload
If mysqld is included in enforce mode, then the entries can be written in /var/log/messages when AppArmor blocks the writes/accesses.
You can edit /etc/apparmor.d/usr.sbin.mysqld and add /home/user/mysql_temp/ and /home/user/mysql_temp/* near the bottom like this:
/usr/sbin/mysqld {
...
/var/log/mysql/ r,
/var/log/mysql/* rw,
/var/run/mysqld/mysqld.pid w,
/var/run/mysqld/mysqld.sock w,
**/home/user/mysql_temp/ r,
/home/user/mysql_temp/* rw,**
}
And then you can make AppArmor reload the profiles.
# sudo /etc/init.d/apparmor reload
WARNING: The above change will allow MySQL to read and write to the /home/user/mysql_temp/ directory.
Change ownership of the specified directory to mysql user.
chown mysql:mysql /data/data-directory
the original question was writing to an outfile here:
INTO OUTFILE '/home/user/mysql_temp/file.csv';
the problem could be a mysql configuration; and not apparmor.
if you are running with systemd, look at this setting in /etc/systemd/system/mysql.service:
# Prevent accessing /home, /root and /run/user
ProtectHome=true
assuming all of the file permissions are correct, one would need to change this to false to write to the /home directory.
After upgading MySQL to newer version I have error when I want to connect to server:
ERROR 1524 (HY000): Plugin '0' is not loaded
Any ideas?
This looks like a Bug in MySQL as Bug #60432
Modifying mysql.user table can deny users from logging in . Which states that:
If database manager accidentally (or deliberately) modifies mysql.user
table by adding any column in position lower (or equal) than
"max_user_connections", then after reloading privileges no one is
allowed to log in.
Workaround: Undoing the modification made in user table.
Run following commands
sudo /etc/init.d/mysql stop
sudo mkdir -p /var/run/mysqld; sudo chown mysql /var/run/mysqld
sudo mysqld_safe --skip-grant-tables &
and then press enter
now your password get reset, you can change your password again
This works for me
This is indeed a bug with MySQL and a changed user table structure. Unfortunately, if you don't know what changed, you can't change it back. Also, if you cannot login, you cannot fix anything either.
I fixed this as follows. Please be careful with these instructions as they may not work entirely for your setup and you could lose your data if this goes wrong. Don't blame me if it does!
1. Back-up old data dir
Back-up your old data dir somewhere. This allows you to restore the tables at the end. To find out where your data dir is, you can try to initialise mysql. It will give you an error because the data dir already exists:
mysqld initialize
Output:
mysqld: Can't create directory '/usr/local/mysql/data/' (Errcode: 13 - Permission denied)
Now backup your data dir somewhere:
cp -r /usr/local/mysql/data ~/backup-dir/
2. Re-initialize MySQL
With your data dir safely backed up, remove it and re-initialize mysql. It will give you a new temporary password which you can change later.
rm -rf /usr/local/mysql/data
mysqld initialise
The output will give you a new password for 'root'. If you get permission errors, use sudo (not sure about the drawbacks).
Start the server using mysqld_safe to be sure it works the first time:
mysqld_safe
Optionally, change the root password by logging in to mysql and running alter table:
mysql -u root -p
<enter password>
ALTER USER 'root'#'localhost' IDENTIFIED BY 'New Password';
3.Restore data
Stop the mysql server
mysqld stop
Copy all the backup files to the new data dir (run this for every db you need to restore):
cp -r ~/backup-dir/data/<dbname> /usr/local/mysql/data/
For MyISAM tables, this is enough. If you have InnoDB tables, you also need to copy the InnoDB table space from your backup:
cp ~/backup-dir/data/ibdata* /usr/local/mysql/data/
Then, fix permissions (look at the files already present in /usr/local/mysql/data for the right permissions, mine were 'mysql' for both user and group):
chown -R mysql:mysql /usr/local/mysql/data/*
Start the mysql server
mysqld start
All done! You should be able to login again and your tables should be back containing all data, too.
I found a way to fix this...
change the configuration file --my.cnf (usually in /etc/my.cnf)
add "skip-grant-tables" below [mysqld]
now you can login the mysql! backup your database and re-install mysql
I think this will completely repair the problems.
(Plugin 0 is not loaded, i found i cant backup the database then..so you need to add something in mysql.cnf)
I restarted my MySql server and Apache web server and it worked.
Problem
I'm running MySQL 5.5.23 on Mac OS 10.8.2 and am unable to drop a particular database, but I can drop others.
When I attempt to drop the specific table I get this error:
#1548 - Cannot load from mysql.proc. The table is probably corrupted
Attempted Fixes
I have restarted the system
I have tried to restart MySQL via CLI
$ sudo /usr/local/mysql/support-files/mysql.server stop
but received this error ERROR! MySQL server PID file could not be found!
I have repaired the mysql.proc table.
REPAIR TABLE mysql.proc
REPAIR TABLE mysql.proc USE_FRM
I have repaired all mysql.* tables.
REPAIR TABLE mysql.*
When running mysqlcheck from the Command Line
mysqlcheck --repair --all-databases
mysqlcheck --repair specific-db
I received this error : mysqlcheck: Got error: 2002: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) when trying to connect
Current Status
I still cannot drop the original specific database, but can drop others.
Update[1] 2013-01-05 11:15 am [New York]
Logs and Feedback (per #Thomas in comments)
To find all logs, I ran (cli):
$(ps auxww|sed -n '/sed -n/d;/mysqld /{s/.* \([^ ]*mysqld\) .*/\1/;p;}') --verbose --help|grep '^log'
I received this feedback:
130105 11:35:21 [Warning] Can't create test file /usr/local/mysql-5.5.23-osx10.6-x86_64/data/wills-mbp.lower-test
130105 11:35:21 [Warning] Can't create test file /usr/local/mysql-5.5.23-osx10.6-x86_64/data/wills-mbp.lower-test
130105 11:35:21 [Note] Plugin 'FEDERATED' is disabled. /usr/local/mysql/bin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
130105 11:35:21 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
I'm looking into the mysql_upgrade.
Update[2] 2013-01-05 4:04 pm [New York]
I ran this :
sudo /usr/local/mysql/support-files/mysql.server stop
And received this error:
ERROR! MySQL server PID file could not be found!
Update[2.1] 2013-01-05 5:37 pm [New York]
I ran ps auxww | grep mysql and found the mysqld process and killed it (sudo kill [process id]). I was then able to restart mysql successfully. However, I'm still having no luck dropping that specific database mentioned above.
Resolved
After trying to manually repair the corruption and many of the suggestions and the other answer listed here, reinstalling mySQL was the only thing that solved my problem.
On a Mac (running 10.8.2) I also had to do some manual deletions for a clean install:
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm /etc/my.cnf
Articles consulted
MySQL duplicates with CONCAT error 1548 - Cannot load from mysql.proc. The table is probably corrupted
SQL error: BIGINT UNSIGNED value is out of range in (…), but it doesn't make sense
How to repair corrupted table
MySQL manager or server PID file could not be found
PHP/MySQL issue after security update 2010-005
mysql problems after Mac OS X software update
How to remove MySQL completely Mac OS X Leopard
I ran into an issue that queries on my databases (named: caloriecalculator) was taking too long and it won't drop at all. I followed these steps below and it fixed my issue:
See all MySQL processes: mysqladmin processlist -u root -p
Kill all processes relating to caloriecalculator as it was blocking my next queries to be executed.
mysqladmin -u root -p kill 4
Now run: drop database caloriecalculator;
I would try:
Backup/save any databases that have important data.
Remove mySQL
Reinstall mySQL
Restore any backed up databases.
I had this happen to me on a Linux server, and the cause was a corrupted database directory.
UPDATE: one thing to do is to go into MySQL database directory and perform a ls -la, to verify that the evil DB is the same as the others as regards permissions, ownership and so on. For example here the 'original' database cannot be dropped (it was created by a stupid tool ran as root):
drwx------ 2 mysql mysql 4096 Aug 27 2015 _db_graph
drwx------ 2 mysql mysql 4096 Jul 13 11:58 _db_xatex
drwxrw-rw- 2 root root 12288 May 18 14:27 _db_xatex_original
drwx------ 2 mysql mysql 12288 Jun 9 08:23 _db_xatex_contab
drwx------ 2 mysql mysql 12288 May 18 17:58 _db_xatex_copy
drwx------ 2 mysql mysql 4096 Nov 24 2016 _db_xatex_test
Running chown mysql:mysql _db_xatex_original; chmod 700 _db_xatex_original would fix the problem (but check inside the directory to verify there too permissions and ownerships are copacetic).
In the end, I employed the following ugly hack (after trying stopping, restarting and repairing whatever could be targeted by a REPAIR):
created a database "scapegoat"
stopped MySQL Server
copied the directory created by MySQL Server, /var/lib/mysql/scapegoat, to /tmp
restarted MySQL Server, dropped the database "scapegoat", stopped the server
Now I had a copy of a clean, empty DB dir that MySQL no longer knew anything about.
moved the "evildb" directory to /tmp (so that if thing went wrong I could put it back)
moved the "scapegoat" directory to /var/lib/mysql renaming it to "evildb"
started MySQL Server
not sure if I ran any more repairs at this point
and the "evildb" database became droppable!
My explanation is that when asked to drop a database, MySQL Server first performs some checks on the files in the database directory. If these checks fail, the drop also fails. These checks must be subtly different from the ones performed by REPAIR. Maybe in the affected directory there is something unexpected.
I think this was on a MySQL 5.1 or 5.2 on a SuSE 11.2 Linux distribution. Hope it helps.
UPDATE
On thinking back, I don't remember getting errors about "proc". So I'm less sure that the problem lies in the directory. It might be connected with the proc table, without being a table corruption. Have you tried visually inspecting the proc database table, in order to find something there that belongs to the evil DB?
USE mysql;
SELECT * FROM proc;
That, or any errors therefrom, could help in solving the problem. You might, who know, have some lines with the wrong db column. In a pinch, you could export the proc table and reload it after cleaning (either through SQL or via a disk file).
TEST
I have partial verification for the above update. By intentionally inserting rubbish into the proc table apropos a newly created database evil, I partially reproduced your symptoms (undroppable database, MySQL connection crashes on attempt). Error number is not 1548 though; but maybe it would be, if I inserted the right rubbish in that table... anyway, the useful bit is that by removing all references to the evil db, the latter became droppable again:
mysql> drop database evil;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> use mysql;
No connection. Trying to reconnect...
Connection id: 1
Current database: *** NONE ***
Database changed
mysql> DELETE FROM proc WHERE db = 'evil';
Query OK, 2 rows affected (0.00 sec)
mysql> drop database evil;
Query OK, 0 rows affected (0.00 sec)
I had the same problem and all I did was to delete the database directory from the mysql data directory.
If you using xampp In windows
you can also drop your database using phpmyadmin
go to home -> databases -> click on your [database name] -> drop
OR
you can also drop your database manually
go to xampp -> mysql -> data -> [database name]
delete your [database name] now.
Following error occurs when I am trying to restore a DB in MYSQL via putty.
Command: mysql -u root -p db1<dbname.sql ;
ERROR 1 (HY000) at line 7904: Can't create/write to file
'./dbname/db.opt' (Errcode: 2)
What is the reason?
This often means that your dump file includes a command that should run against a database that either doesn't exist in your local context, or to which the current user does not have access. Open up the dumpfile and look at the line mentioned in the error to find out what's going on.
I ran into this error at work when the source database name was different than the target database name. I dumped a database on one server with mysqldump db1 > dumpfile and attempted to import it on a different server with mysql db2 < dumpfile.
Turns out the dumpfile had ALTER TABLE db1 ... statements which were meaningless on the target server where I named the database db2.
There is probably a more elegant solution than this, but I just edited the dumpfile on the target server and replaced db1 with db2.
Find out what Errcode: 2 means
You can use the perror utility to find what error 2 means:
$ perror 2
OS error code 2: No such file or directory
More info is at the link #Jocelyn mentioned in their comment: http://dev.mysql.com/doc/refman/5.5/en/cannot-create.html
Find out what path ./ points to
We now know a file doesn't exist (or maybe it can't be written to.) The error message gives us a relative path ./ which makes it tricky... Wouldn't it be helpful if it output a fully-qualified path? Yeah.
So when MySQL imports an SQL file it creates some temp files on the filesystem. The path is usually specified by the "tmpfile" configuration option in the MySQL my.cnf file. You can quickly find the value by executing an SQL query:
$ mysql -h127.0.0.1 -uroot -p
# I assume you're now logged into MySQL
mysql> SHOW VARIABLES LIKE '%tmpdir%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| slave_load_tmpdir | /tmp |
| tmpdir | /tmp |
+-------------------+-------+
2 rows in set (0.00 sec)
Ensure the directory is writeable by mysql user
According to tmpdir this means MySQL was trying to create /tmp/dbnamehere/db.opt. Ensure this directory exists and that it's owned by mysql:mysql. You might have to use sudo to elevate privileges high enough to create some directories.
$ chown -R mysql:mysql /tmp/dbnamehere
Still not working? Try other default tmpdir paths
I hit issues on my system (Ubuntu 12.04 + Vagrant 1.7.2 + Chef 11.something + opscode mysql cookbook 6.0.6) where the value in tmpdir wasn't being considered or wasn't being pulled from where I expected.
MySQL was actually trying to create the temp file at one of the following locations:
/var/lib/mysql/dbnamehere
/var/lib/mysql-default/dbnamehere
I had to create those directories and change ownership to mysql:mysql.
I had backup from "db1" and restoring to "db2"
so in the dump file had to change "db1" to "db2" with sed.
And all worked fine.
You'll find help about this error in the MySQL manual: http://dev.mysql.com/doc/refman/5.5/en/cannot-create.html
I installed LAMP on Ubuntu 11.04 and copy project from Windows.
PHP directory (/ci/) to var/www/
and
MySQL project directory (/ci/) to var/lib/mysql/
Full text of error that i get:
A Database Error Occurred
Error Number: 1017
Can't find file: './ci/users.frm' (errno: 13)
SELECT COUNT(*) AS `numrows` FROM (`users`) WHERE `email` = 'admin#localsite.com'
I googled that its permission problem, but don't know what do next.
Log from /var/log/mysql/error.log:
110622 19:27:21 [ERROR] /usr/sbin/mysqld: Can't find file: './ci/users.frm' (errno: 13)
Permissions problem meaning the permissions on the file. MySQL probably can't read it. Just change the owner and group to mysql and it should work.
chown mysql:mysql /var/lib/mysql/ci/*
As well as the files being readable by the MySQL user, the directory containing the .MYI files needs to be read, write and executable by the MySQL user. On my system this was achieved by:
chown -R mysql:mysql /var/lib/mysql/dbname
chmod -R 660 /var/lib/mysql/dbname
chown mysql:mysql /var/lib/mysql/dbname
chmod 700 /var/lib/mysql/dbname
This is an old topic, but I didn't find anything that worked for me so for anyone running into the same problem, yet the above file permission suggestions still don't change the "Can't find file" errors, here's what worked for me and my particular issue.
I was doing a rescue from one CentOS server to another using a recovery image, which had a different OS than the original OS and the original filesystem was mounted on a temporary dir. While I had access to the original /var/lib/mysql files, I didn't have access to the mysql admin or dump utilities, which requires the server to be running anyway (it's not automatically included when doing a recovery from a read-only image). Backups were a week old and I wanted to see if I could get the most recent data possible.
Changing the standard file permissions on these still kept giving "Can't find file" for nearly all of the database tables, however I could see that the tables were there. Turns out it was related to SELinux context on the files I had moved over using rysnc. All of the rescued dirs and files looked like this:
$ ls -alZ
drwx------. mysql mysql unconfined_u:object_r:admin_home_t:s0 somedb_dev
drwx------. mysql mysql unconfined_u:object_r:admin_home_t:s0 somedb_local
drwx------. mysql mysql unconfined_u:object_r:admin_home_t:s0 somedb_production
drwx------. mysql mysql unconfined_u:object_r:admin_home_t:s0 somedb_staging
The -Z flag notes the security context of files and dirs. Notice the unconfined_u and admin_home_t context. These are different from what they should be:
drwx------. mysql mysql system_u:object_r:mysqld_db_t:s0 mysql
Changing these database files to the proper context solved the problem and gave proper access to mysqld using the chcon command:
$ chcon -R -u system_u -t mysqld_db_t somedb_*
This changed all my custom databases to the proper SELinux context and the files could now be recognized by mysqld. I recommend running the chcon commad while the database server is not active, just as a precaution.
Hope that helps someone running into the same problem I had! Of course, you can turn off SELinux temporarily to test if this is fact this issue, but I didn't want turning off SELinux as a permanent solution.
I followed this steps:
Stop the mysql service.
Modify the my.cnf line datadir to my custom location.
Deleted all the files ib_data* , ib_logfile* in our new custom location
Change the permissions of the entire folder with your sentence:
chown mysql:mysql -R /custom_location/mysql/*
Start again the mysql service.
It works!!
Thanks
This error also occurs if the table is not in the database; so if you changed permissions of the directory and are still running into issues check your database and make sure the table is there.
So let's say you got an error like the OP:
Can't find file: './ci/users.frm'
ci is the database name
users is the table name
So in this case if you changed permissions and still had this issue you would verify that the users table is in the ci database.
#Brent Baisley It does work in XAMPP for Linux, but the location is different.
I did upgrade the Kernel today to fix the new Linux “Dirty Cow” Vulnerability (CVE-2016-5195). After the reboot I got the 'frm' permission error too.
So, if you get the following error:
Can't find file: 'yourtablename.frm' (errno: 13 - Permission denied) SQL query :...
You can do:
chown mysql:mysql /opt/lampp/var/mysql/yourDBname/*.frm
This will resolve your issue.
If you'd like to check, if your permission to any of the files has been modified before you execute the permission change, do:
ls -l /opt/lampp/var/mysql/yourDBname/*.frm
Hope that helps someone.
If you have failed RENAME TABLE statement, it could leave MySQL metadata in bad state. The solution is to recreate schema or to recreate table.