LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-14-2013, 06:22 AM   #16
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled

Quote:
Originally Posted by jonaskellens View Post
To grant "file" to a user other than root seems very dangerous...

I can't seem to find an alternative to import a csv-file into MySQL.
really? how about the root mysql-user?

I have Never used the file perm, nor have I Ever assigned it to anyone, nor never needed to for an import.
mysql -u <mysql_privileged_user> -p <db> < file.sql
 
Old 05-14-2013, 06:49 AM   #17
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
http://www.linuxquestions.org/questi...pt-4175461780/
 
Old 05-14-2013, 07:36 AM   #18
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by Habitual View Post
mysql -u <mysql_privileged_user> -p <db> < file.sql
This is no alternative to import a csv-file. Like I said earlier I have no sql-file but a csv-file.
 
Old 05-14-2013, 07:43 AM   #19
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by chrism01 View Post
bash is interpreted, I believe php is not, so php should be faster & less resources.
Then I will use php and my problem of importing csv-data into external MySQL-database will also be solved I guess.
 
Old 05-14-2013, 07:56 AM   #20
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
try http://dev.mysql.com/doc/refman/5.0/...ort.html#c5680

<IMO>I am not certain that "GRANT FILE" is what you really need to get this job done.</IMO>

typically, I'd load data as root into a specific mysql_db, this way I only have to worry about what I do to the db, NOT worry about THE USER
trashing stuff.
the .csv may need some "massaging", or manipulation.

See also:
http://stackoverflow.com/questions/6...a-command-line
http://kurinchilamp.kurinchilion.com...mand-line.html
and
http://alvinalexander.com/blog/post/...database-table

Good luck.
 
Old 05-14-2013, 08:05 AM   #21
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by Habitual View Post
typically, I'd load data as root into a specific mysql_db
I can not reveal root login information inside the bash script.
 
Old 05-14-2013, 09:03 AM   #22
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by jonaskellens View Post
I can not reveal root login information inside the bash script.
Who said anything about revealing any passwords?
http://kurinchilamp.kurinchilion.com...mand-line.html

If you want to be spoon-fed, I charge $1000.00 per hour USD.

Easy answer: and the sanest, Create a csv-only user.
Code:
mysql -u root -p grant all privileges on dbname.* to csv_import@localhost ‘IDENTIFIED BY ‘n4Tur3aL’; flush privileges;"
then use mysql -u csv_import -p n4Tur3aL and work the import using those credentials.

Last edited by Habitual; 05-14-2013 at 09:13 AM.
 
Old 05-14-2013, 09:15 AM   #23
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
In your link passwords are revealed. This is not useful. Even if you charge $50.00 I would not recommend you.

Meanwhile I found another solution combining php and bash, which gives me the best of both worlds.
 
Old 05-14-2013, 09:16 AM   #24
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Hi. Why are you trying to import the rest of the file into a sql database? I dont like the idea. I make a shell script, and make a sql file, then import the sql file with the shell script.

Anyway... try this in your script.


Code:
#!/bin/bash -l

mysql -u MyUser -pMyPassword -h ip_databaseserver -D My-DB < some_file.sql
 
Old 05-14-2013, 09:29 AM   #25
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by jonaskellens View Post
In your link passwords are revealed.
Big Fargin' Deal. Change it?
Quote:
This is not useful.
Again with the "spoon-feed me" response.
Quote:
Even if you charge $50.00 I would not recommend you.
I'm not sure you could count it.

Quote:
Meanwhile I found another solution combining php and bash, which gives me the best of both worlds.
You are all over the map on this "solution".

Good luck.
 
Old 05-14-2013, 09:43 AM   #26
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by szboardstretcher View Post
Hi. Why are you trying to import the rest of the file into a sql database? I dont like the idea. I make a shell script, and make a sql file, then import the sql file with the shell script.
We have software that produces csv-files.

What I wanted is a bash script that puts the content of these csv-files into a remote MySQL-database.

But I was getting the error in my original post, which seemed to be related to the lack of the "FILE"-permission of the database user.

Adding the "FILE"-permission to the user seemed unsafe.

So that is where I stranded with the bash-script.

Found another way to implement using php and bash.

Thanks.
 
Old 05-14-2013, 09:49 AM   #27
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Quote:
Originally Posted by jonaskellens View Post
Found another way to implement using php and bash.
Good to hear. Mind sharing the php/bash way with us, so this thread can be useful to someone in the future?
 
Old 05-14-2013, 09:18 PM   #28
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Merged the two VERY closely related threads.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does this work from the bash command line and then fails in a bash script? Rupadhya Linux - Newbie 5 09-26-2012 12:05 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
Can MySQL log on via SSH/bash? mysql:x:27:101:MySQL Server:/var/lib/mysql:/bin/bash Ujjain Linux - Newbie 2 04-24-2009 02:21 PM
Bash script run via cron not executing MYSQL command mackstar Linux - Server 4 04-23-2009 05:01 AM
Is 'nice' inherited to child processes? e.g. bash script/php script that calls MySQL SirTristan Linux - Newbie 1 12-04-2008 12:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration