I am trying to use the LOAD DATA INFILE MySQL command on a Raspberry Pi running Raspbian. There are lot of similar questions on here but none seems to answer my problem exactly.
My code works fine on my Windows dev machine but on the Pi I get this error:
Can't get stat of '/var/www/transfer/categories.csv' (Errcode: 13)
Mysql statement is:
LOAD DATA INFILE '/var/www/transfer/categories.csv'
IGNORE INTO TABLE category
FIELDS TERMINATED BY ',' ENCLOSED BY '"';
The code is running in PHP and the database is MySQL.
The file and its '/transfer' folder have read permissions for World.
I have read a little about apparmor but can't see how to check or change how it is configured. There are 2 files in the /etc/apparmor.d folder. One is .usr.sbin.mysqld.swp but it doesn't seem to contain text and the other file refers to lightdm.
The database server and client is on the same server, so the LOCAL keyword doesn't apply.
My MySQL user has global privileges, so includes the FILE privilege.
I have checked the secure_file_priv setting and there is none.
I am sure this is some sort of permission or privilege issue, but I've run out of ideas. I want the file to live under the www folder because the system user has FTP rights to put it there. Ultimately I want to also create the file on the same machine but for now I'm happy to just read the file created under Windows.
$ errno 13
EACCES 13 Permission denied
Check your permissions; especially folder permissions. You can try su or sudo -u to the MySQL user and running ls -la /var/www/transfer/; if you don't see anything then you know the issue has to do with permissions of the folder and/or its contents.
If MySQL is running locally; to see which user: ps -elf | grep mysql
To switch to the MySQL user and test: sudo -u <mysql> bash
Related
I am unable to write tab separated text files into specified TSV/ folder using mysqldump on WINDOWS10 (MySQL80 service).
The Command prompt (or powershell) is in admin mode.
secure-file-priv ="" in my.ini MySQL config file.
MySQL was installed on my local computer and I use a localhost connection with the root username.
Command is:
mysqldump -T C:\Users\...\20200430_Dump\TSV\ --user root -p database_name
OUTPUT:
mysqldump: Got error: 1: Can't create/write to file 'C:\Users...\20200430_Dump\TSV\table_name.txt' (OS errno 13 - Permission denied) when executing 'SELECT INTO OUTFILE'.
They are many related post on LINUX but I am specifically looking for an solution for WINDOWS
My small hypothesis:
Some linux posts suggest that mysqld use a specific user-account (that seems to be mysql in linux but this is unfortunately not documented at all for any OS). So I imagine that when the server is executing INTO OUTFILE queries he needs to have permission for the TSV/ folder, but i do not know how to do give him this permission in WINDOWS.
best
Left click on your TSV/ folder > Properties > Security Tab > Edit > Add
You need to add NETWORK SERVICE in Group or User names with Full control privilege (probably just Write is sufficient).
The mysqldump now works (tested on windows10)
You need to create an empty SQL file and specify the path to it.
I created MySQL cluster of nodes (2 datanodes, 1 management node, and 1 MySQL server node) on Docker Following the instructions from this link:
https://mysqlmed.wordpress.com/2017/09/04/mysql-cluster-in-docker-quick-step-by-step
Then I created a MySQL table to import a csv file (named daily.csv) using the command:
LOAD DATA INFILE 'C:/Users/Utilisateur/Desktop/daily.csv' INTO TABLE daily IGNORE 1 LINES;
and I got the error:
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement.
When I add LOAD DATA LOCAL INFILE ..
I get this error:
ERROR 2 (HY000): File 'C:/Users/Utilisateur/Desktop/daily.csv' not found (Errcode: 2 - No such file or directory)
When i check my secure-file-priv using the command:
SELECT ##global.secure_file_priv
I get the Following path: /var/lib/mysql-files/ but I have no idea how to access to it in order to copy my csv file, or even to access my.ini MySQL config file to change the variable secure-file-priv into NULL, which as I saw is another solution to get permissions to access my file.
As I am using Docker, I have no idea how to access the MySQL container config file.
I tried many ways but I see no issue. Could you please help me with this I would be very delighted as I spent a lot of time trying to fix it??
I followed these instructions but don't know where the file /etc/mysql/my.cnf to change the variable secure_file_priv to NULL is:
Mysql making --secure-file-priv option to NULL
In your case it might be sufficient to mount your local directory inside the directory expected by mysql (/var/lib/mysql-files/).
Try starting the container with an additional -v parameter, like this:
docker run -d -v C:/Users/Utilisateur/Desktop/:/var/lib/mysql-files --net=cluster --name=mysql1 --ip=192.168.0.10 -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql/mysql-cluster mysqld
Or copy the file into the folder:
docker cp C:/Users/Utilisateur/Desktop/daily.csv mysql1:/var/lib/mysql-files
assuming the name of your container is mysql1, as in the link you provided.
Linux. No SELinux (disabled).
I try to run this command as my linuxuser (member of group mysql):
mysqldump --user=root --tab "/some/folder" dbname
Getting this error:
mysqldump: Got error: 1: "Can't create/write to file 'sometable.txt' (Errcode: 13 "Permission denied")" when executing 'SELECT INTO OUTFILE'
If I look in the folder, there is a sometable.sql file, but no txt file.
As I understand, the sql file is created from the user's name who run the command (linuxuser in my case), but the txt file gets generated by mysql server (mysql user in this case). Note that mysql user is also a member of mysql group.
What could be the problem? Tried everything :)
If you trying to execute a mysqldump in a client diferent that the server
can be a problem
I tried with mysqldump Ver 10.14 Distrib 5.5.56-MariaDB, for Linux (x86_64), and works only with the /tmp/ dir.
Perhaps, help info say that will not work
-T, --tab=name Create tab-separated textfile for each table to given path. (Create .sql and .txt files.) NOTE: This only works if mysqldump is run on the same machine as the mysqld server.
The solution was to change "some/folder" to an external location. Looks like there were permission problems because originally the folder mentioned was under Perforce root and probably it had read-only permissions.
I then changed the new folder permissions to:
mylinuxuser:mysql
making sure that both the user with which the process was started, as well as mysql server have permissions to write there. This is because the sql file is written from user's name and txt file is written from mysql server's name.
I also added my user to the mysql group.
This was something I just found and wanted to pass along for the folks searching for the same answer.
This has been occurring on systems running systemd. In the /lib/systemd/system/mariadb.service file is the setting, 'PrivateTmp=true'. This is a security measure to prevent the data from being seen by folks who shouldn't be seeing it.
If you run:
SELECT * TO OUTFILE '/var/tmp/tablename.txt' FROM TABLENAME;
It will create the file but it creates it in a systemd protected directory.
/var/tmp/systemd-private-[hash]-mariadb-[hash]/tmp/tablename.txt
You can either save the data from here which is perfectly acceptable or stop mariadb, create the directory /etc/systemd/system/mariadb.service.d and in that directory create the file 'mariadb.conf' (as an example; any file should do) with the following:
[Service]
PrivateTmp=false
Run systemctl daemon-reload to reload the configuration and restart mariadb.
You should be able to create backups now.
What has worked for me (in Windows), trying to export a file using:
SELECT * INTO OUTFILE 'C:/documents/dumps' from file
MySQL Service properties --> Log on: take note account defined.
Directory C:\documents\dumps --> properties --> Security: account defined above needs read/write privileges
I am attempting to upload a .txt file into my sql database I just created.
I was able to load several lines of data into the table using INSERT INTO, but when I tried to utilize LOAD DATA LOCAL INFILE '/pathto/file.txt' INTO TABLE mytable, it first gave me the error that command is not allowed in my version of mysql.
So after I read How can I correct MySQL Load Error, I used the --local-infile=1 -u mysqlname -p followed by the above command I have repeatedly been awarded the syntax error.
I've tried this to load the .txt file with all sorts of different combinations of the above, and still get one of the two errors.
Below is a screen shot.
This is with ubuntu 15.10 and mysql version 5.6.28-0ubuntu0.15.10.1.
Screen shot of terminal in question
--local-infile is a server and client parameter. It's not valid syntax as part of a statement such as LOAD DATA or INSERT statement.
You would specify server variables and options either in the appropriate sections of the my.cnf file, or as command line parameters to the MySQL program being executed.
For example, at the OS prompt...
# mysql -h myserverhost -u mysqlname -p --local-infile=1
That option has to be specified for the MySQL server.
If you are connecting as user#localhost, you don't need LOCAL. You can give the MySQL user (whichever OS user the mysql server is running under) read privilege on the file you want to load... chmod ugo+r /mypath/myfile (and read execute on the directories in the path.
You only need LOCAL if the msyql user isn't #'localhost'.
I want to copy the database tables from my production server to a local test machine so I can perform test om (copies of) the real data.
I stopped mysql and deleted all the frm, MYD and MYI files. Starting mysql here and querying show tables gives an empty result set. I then shut down mysql and copied all the frm, MYD and MYI files from the server. When starting mysql "show tables" shows the tables as expected but trying to query them I get the error message
ERROR 1017 (HY000): Can't find file: './WhateverTableIQuery.frm'
(errno: 13)
But the WhateverTableIQuery.frm file is on the disc and is identical to the one on the server.
Any ideas about what might be the problem?
I'd suggest giving two things a try:
1. Check Permissions
Make sure that your MySQL data directory and all the files in it are owned by mysql user and mysql group. This may not be the case if you copied the files onto your local test machine as root user:
chown -R mysql:mysql your-mysql-data-dir-here
2. Repair corrupted tables
Use mysqlcheck to check for corrupted tables and repair them if it finds any:
mysqlcheck -u root -p --auto-repair --all-databases
If you still can't use the tables after that then give mysqldump a go!
I encountered the same issue after restoring a MySQL database with frm and MYD files. After a number of hours spent I observed that I have configured the database directory with only read and write permission to mysql user but not execute permission. After adding execute permission to the database directory, the problem was solved.
I did have the very same issue a couple minutes ago and it took me a few minutes to realize that I had insufficient permission to access the .sql file I wanted to import.
In order to get rid of this problem you could just move the file to a place you know you have access to (with your current user) for sure. (eg. ~/Home_directory).
I hope I could help some lonely soul that was searching for the answer just like I was.
I had the same issue and did this...
Delete Migrations Folder
Drop the _migrationhistory table
Enable, Add and Update migration
I'm sure there's a much better way to solve this but, it worked for me.
I changed permissions for the mysql-data-directory as well as the <table>.frm file.
If using as root user:
chmod 600 mysql-data-directory chmod 600
mysql-data-directory/tableOfData.frm
If using as non-root user:
chmod 660 mysql-data-directory
chmod 660 mysql-data-directory/tableOfData.frm
This error, "General error: 1017 Can't find file", also happened on Windows with WAMP if the table doesn't exist.
Try following things:
repair whole database
change permission to mysql:mysql
restart mysql service
One of these will work.