Dumping a database table to text file - mysql

I am trying to dump a table from MySQL database into a text file by running the following query
SELECT fields FROM text_file_table INTO OUTFILE 'C:\\Program Files\\textfile.text'
But it gives me the error
Cant create/write to file "C:\Program Files\textfile.text"
I think it is due to security issue, that it is not allowing the DBMS to write the file on that directory. If there can be any other issue, please let me know, and also help me finding solution to the problem. And I am doing this on Windows Server 2008. Thanks!

There could be two issues. The command runs in the operating system as 'mysql' so the 'mysql' user may not have permission to write in c:\Program Files. It shouldn't, so that's good. If you change your target path to somewhere that you can write to, this problem will go away.
The other issue is that the user you are logged in as inside mysql may not have the privilege to read and write files - see http://dev.mysql.com/doc/refman/5.1/en/privileges-provided.html#priv_file. If this is the problem, you'll have to GRANT the privilege to your user.

I think problem is with the path . if you are using windows
the filepath sould be like this in the query
'C:/Program Files/textfile.txt'
OR try this , i am not sure
'C:\Program Files\textfile.txt'
also use txt inside of text in the file name => textfile.text

Related

Can't open CloudSQL binlog: "No such file or directory"

I am trying to view the MySQL binlog files to trace down the source of a particular query. I used the SHOW BINARY LOGS query to get the names of the existing log files, but when trying to access using the mysqlbinlog command, I keep getting an error: "File 'xxxx' not found (Errocode: 2 "No such file or directory")".
I also tried accessing the file using the full path /mysql/binlog/mysql-bin/file-name and with double forward slashes and back slashes, but just got the same error. I tried a couple of different files, all gave the same error.
If anyone can explain what I am doing wrong, that would be appreciated.
Mysqlbinlog utility checks your local file system, in this case. For remote server connection, you should use the --read-from-remote-server option in your command line. You can read related detail on the "4.6.8 mysqlbinlog — Utility for Processing Binary Log Files" page.

Import data from txt file to mysql workbench - windows

I have a kind of huge amount of data on a .txt file (something like 90.000 lines and 10 columns, each 'item' separed by comma) and I need to find a way to import it from my txt file to a mysql table.
I did some research and found the following code:
LOAD DATA INFILE "/my_path/file.txt" INTO TABLE "table" CHARACTER SET "utf8" FIELDS TERMINATED BY "," LINES TERMINATED BY "\r\n";
but that gives me the following error:
Error Code: 29. File '/my_path/file.txt' not found (OS errno 13 - Permission denied) 0.000 sec
So after searching a little bit more, I found that a lot of people had this issue but solved just by putting the word 'LOCAL' (LOAD DATA LOCAL INFILE), but that gives me this error:
Error Code: 1148. The used command is not allowed with this MySQL version 0.000 sec
(I'm using MySQL Workbench 8.0)
So I tried to set some global variables like secure-file-priv="", loose-local-infile=1 and local-infile=1 in my my.ini file, but nothing seems to work.
Can anyone help me please...
Ps 1: I can't use the wizard import because even though it would work, it's too slow
Ps 2: I tried to convert my txt file to csv but it didn't work either.
Without LOCAL, LOAD DATA INFILE tells the MySQL server to find the file on the file system of its own machine and read it.
So, the path and file have to exist on the server machine. And, the credentials (the username) under which the MySQL server runs must have read access to the file.
Your permission denied error hints to me that the MySQL server can't read the file.
The OP had 2 problems:
a) mysql did not have access to the input file from a permissions perspective
b) the input file was not correctly encoded.
Once the access issue was resolved and the input file encoding had been corrected to utf8, the load worked correctly.

Create tablespace "error in creating database file, access denied (OS 5)"

I try to create a database file. I've checked the route and everything, I've tried several times to create the tablespace (I've changed to capital letter, the ' for "...) like this...
create tablespace uinstitucion datafile 'C:\app\uinstitucion\oradata\uinstitucion\uinstitucion.dbf' size 500M ;
file create error, unable to create file", "unable to open file", "(OS 5) access denied" (but I am logged as SYSTEM!)
... as you can see, I was just lead to several errors. What can I do? What am I doing wrong? I'm desperate since yesterday, and my teacher does not seem to notice the exact error.
I've also tried the order like
CREATE TABLESPACE lmtbsb DATAFILE 'file_path/lmtbsb01.dbf' SIZE 50M
EXTENT MANAGEMENT LOCAL AUTOALLOCATE;
but it leads me to the same error.
I'm sorry I cannot post a picture, it would be more descriptive, but I am not allowed yet.
Please run your SQLplus as an administrator and then connect and try to execute it.
You error says that you have no privileges to create file. This comes from operating system. Path looks for Windows so please try right click on SQLplus (or any other client you're using), choose run as administrator and then continue.

Easy PHP and mysql ..php cannot see database on local pc (all works on server)

I have a website written in php and mysql (written by someone else) and I need to alter it- just for your interest it is bridgetjonesart.co.uk. So I thought I would download it to my desktop pc and use easy php and mysql locally to make changes then upload it again.
I seem to have downloaded everything okay. I first just tried to run existing php using Easy Php and got
Warning: mysql_connect(): Access denied for user 'runningc'#'localhost' (using password: YES) in C:\Program Files (x86)\EasyPHP-12.1\www\backup from runningc\public_html\bridgetjonesart.co.uk\mysqlLogin\mysql_connect.php on line 6
Could not connect to database. Error
I have the sql database as a file 'runningc_bjart.sql' in the root directory but I think the php cant see it so I tried to use easy php administration, phpmyadmin and thought perhaps I should import the 'runningc_bjart.sql' file. So I tried and got an error message ...
Error
SQL query:
--
-- Table structure for table `Blog`
--
DROP TABLE IF EXISTS `Blog` ;
MySQL said: Documentation
#1046 - No database selected
I am not sure what to try next, any help would be really appreciated.
Thank you. Bridget
The error messages are VERY clear.
Error #1: You're using the incorrect credentials, or have forgotten to grant rights on your database to the credentials you're using.
Error #2: You've forgotten to set a default database, so MySQL has no idea which database it should be looking in for the table you're trying to drop.
e.g. you need
mysql_select_db('mydatabase');
or change your DROP query to be
DROP TABLE mydatabase.Blog;
With phpmyadmin, create a new database named runningc_bjart and import the file there. Then search in your project for a config file where the db password is set and change it with your local mysql password

MySQL can't write to file, permission denied. (Error 13)

I have a web application that runs queries on the database. The application is trying to run a query, and send the results to the an output file. I have confirmed that the issue is actually a permission denied (error 13) problem, not an issue with any other part of the query. A simplified form of the query follows:
SELECT 'anything'
INTO OUTFILE '/var/www/html/sl/filestore/dbadpt_database.tmp'
FROM INFORMATION_SCHEMA.TABLES;
This query runs fine when I remove the INTO OUTFILE line. I have tried every permissions setting for this dir that I can think of. I have even changed the permission to 777, and gotten the same results. (Yes, I know 777 is not secure. Just did it for testing) I have tried every ownership combination of 'root', 'apache', and 'mysql' that I could think to try for this dir. I have pasted the above query into the MySQL command-line tool, and it has produced the same results.
We are running CentOS 5.5. The web server running the application is Apache 2. I cannot create the file ahead of time, nor can I change the directory that the program is trying to write to.
I would hazard a guess that problem is with SELinux.
The first thing I would try would be setenforce 0 and see if that fixed it. It will only fix the symptoms (you still need to reconfigure SELinux to allow what you need), but it will at least confirm whether that's the problem or not.