LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-03-2014, 01:58 PM   #1
keithostertag
Member
 
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127

Rep: Reputation: Disabled
MySQL- how to configure for temporary script path? Linux


I am just starting to look at MySQL. Loaded and running, on Debian.

I get lots of scripts from books and online for study. I don't know the best place to put them.

Evidently, the default would be the datadir which from /etc/mysql.my.cnf is = /var/lib/mysql. That seems like an odd place to dump a bunch of temporary educational scripts.

It would also be nice to not need to type a long absolute path each time I try out another script (using SOURCE).

Ideas?

Thanks,
Keith Ostertag
 
Old 12-03-2014, 02:26 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I wouldn't put anything in /var/lib/mysql

How about making a /usr/src/tmp directory and sticking them there? That's easy to type for sourcing.
 
Old 12-03-2014, 02:53 PM   #3
keithostertag
Member
 
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127

Original Poster
Rep: Reputation: Disabled
OK thanks.

But then how should I configure that path into mysql?

I could edit the my.cnf so that datadir= /usr/src/tmp or wherever. Is that the preferred method? (changing the default datadir)

Is there a way to simply add /usr/src/tmp (or wherever) to an existing path search that the program will check for scripts, or other data?

Thanks,
Keith
 
Old 12-03-2014, 03:44 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
You might have to provide some additional information but I assume by scripts they are either bash scripts or files containing SQL statements that you run via mysql. You do not have to configure mysql.

I would create a subdirectory in your home directory as whatever name you desire. You could add that directory to your path but not sure it is really necessary. Just change to that directory and edit run etc your scripts.

Last edited by michaelk; 12-03-2014 at 03:47 PM.
 
Old 12-03-2014, 04:34 PM   #5
keithostertag
Member
 
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127

Original Poster
Rep: Reputation: Disabled
Hi Michael-

OK, thanks for responding. The scripts are just text files containing sql language statements, and end in .sql.

Yes, I can (and have) created a subdirectory for scripts. I can access them with SOURCE <path_to_file>;

My question really is asking where the normal conventional place to put such temporary scripts, or how to configure mysql to look for them in a path. Like Habitual suggests, I hesitate to put them in the default datadir.

In looking through several documents I failed to find any path that mysql uses, other than the defaults in my.cnf. Evidently the syntax of my.cnf does not allow more than a single absolute path for any given option. So I must be missing something.

Yes, I can (and did) put a subdirectory of these scripts in my path (using ~/.bashrc), but mysql does not search the user system path.

So, yes, I can access the scripts with:

Code:
mysql> SOURCE /home/keith/sql/filename.sql
but I was hoping there was an easier/shorter way to do this so I could just use

Code:
mysql> SOURCE filename.sql
Thanks,
Keith Ostertag
 
Old 12-03-2014, 07:50 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by keithostertag View Post
My question really is asking where the normal conventional place to put such temporary scripts, or how to configure mysql to look for them in a path. Like Habitual suggests, I hesitate to put them in the default datadir.
Keith: I use this to load data (if that's what your doing here)

Code:
mysql -u<user> -p<pass> db_name < /path/to/file.sql
or
cd /usr/src/tmp
Code:
mysql -u<user> -p<pass> db_name < ./file.sql
Does sourcing inside a mysql environment not do a data import?
 
Old 12-03-2014, 08:28 PM   #7
keithostertag
Member
 
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127

Original Poster
Rep: Reputation: Disabled
Hi Habitual-

Oh... OK. So you put your *.sql files in /usr/src/tmp? So then you can cd /usr/src/tmp, then invoke mysql. That way the current working directory holds the scripts, and mysql sees them without using a path or or any configured subdirectory.

Yes, that works... don't know why I didn't think of that. So in my case I first cd /home/keith/sql/, then invoke mysql as usual.

I use SOURCE inside mysql because as I'm studying I am occassionally calling up dozens of demonstration *.sql scripts (one-at-a-time!) downloaded from online along with various sample databases. I'm not sourcing data- just scripts with sql statements, although I guess one could source data that way as well.

Thanks,
Keith Ostertag
 
Old 12-04-2014, 01:45 AM   #8
kevinmilan2014
LQ Newbie
 
Registered: Nov 2014
Posts: 17

Rep: Reputation: 1
When you execute your script, it gets a new shell environment. Thus when you export variables, you are exporting it to the new shell environment and not its parent environment. As far as I know, there is no way to access the parent environment. However, since you are using bash, there may be a few solutions:

Use source

Rather than execute the script like this: /path/to/init.sh do source /path/to/init.sh

From the bash man page:

Code:
source filename [arguments]

Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename.
Make your script a shell function and put it in
Code:
.bashrc
]

Another option is to make init a function and put it in .bashrc like this:

Code:
function init {
    export PATH=$PATH:/home/me/morph_numsys/software/bin
}
Then from the terminal you can just run init.
 
Old 12-04-2014, 01:53 AM   #9
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by kevinmilan2014 View Post
When you execute your script, it gets a new shell environment. Thus when you export variables, you are exporting it to the new shell environment and not its parent environment. As far as I know, there is no way to access the parent environment. However, since you are using bash, there may be a few solutions:
...
I don't see how you reply relates to the OP's question. Perhaps you should re-read and rethink your response to keep the posted information more relevant.
 
  


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
script to read path from console and used to change the script execution path vdamgo Linux - General 5 02-12-2013 02:18 PM
LXer: What are MySQL Temporary Tables? LXer Syndicated Linux News 0 06-15-2012 01:30 AM
i have small project of php script and mysql database, want to configure in .deb file bhanu055 Linux - Software 1 07-25-2011 10:25 PM
LXer: Using Temporary Tables to Speed Up MySQL LXer Syndicated Linux News 0 10-31-2009 01:30 AM
How do you configure the temporary bypass feature of Dansguardian keithdj Linux - Security 1 10-19-2006 09:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:04 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