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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-03-2014, 02:58 PM
|
#1
|
Member
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127
Rep: 
|
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
|
|
|
12-03-2014, 03:26 PM
|
#2
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
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.
|
|
|
12-03-2014, 03:53 PM
|
#3
|
Member
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127
Original Poster
Rep: 
|
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
|
|
|
12-03-2014, 04:44 PM
|
#4
|
Moderator
Registered: Aug 2002
Posts: 26,540
|
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 04:47 PM.
|
|
|
12-03-2014, 05:34 PM
|
#5
|
Member
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127
Original Poster
Rep: 
|
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
|
|
|
12-03-2014, 08:50 PM
|
#6
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
Quote:
Originally Posted by keithostertag
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?
|
|
|
12-03-2014, 09:28 PM
|
#7
|
Member
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127
Original Poster
Rep: 
|
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
|
|
|
12-04-2014, 02:45 AM
|
#8
|
LQ Newbie
Registered: Nov 2014
Posts: 17
Rep: 
|
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 ]
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.
|
|
|
12-04-2014, 02:53 AM
|
#9
|
Moderator
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,315
|
Quote:
Originally Posted by kevinmilan2014
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.
|
|
|
All times are GMT -5. The time now is 11:09 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|