Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all, first off my apologies for what is probably a very basic question but I am pretty stumped as Im used to Windows and Windows Server. Last night I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2013
    Posts
    4

    Linux Noob, (stupid question)


    Hi all, first off my apologies for what is probably a very basic question but I am pretty stumped as Im used to Windows and Windows Server.

    Last night I installed Ubuntu Server and set it up as a web server on a Virtual Machine. That all went fine. I have installed mySql, surprisingly easier than doing it on windows.

    However I have now run into a problem with a sql script file.

    I am user stewart. When I log onto my web server, I get the following prompt

    stewart at web-server:~$

    I have created a directory call SQL

    when I use the ls command the only directory that pops up is SQL.

    Within the SQL directory is a file I have created called
    create-tbl.sql

    Now when I go into mysql I have tried the follwing commands

    SOURCE /home/SQL/create-tbl.sql
    SOURCE /SQL/create-tbl.sql
    SOURCE /stewart/SQL/create-tbl.sql

    None of which work and I am hitting a brick wall for something that should be relatively easy. I could use mySQL in windows instead but I would like to get used to Linux as we have it at work and I am going to have to use it sooner or later.

    Thanks in advance for any help

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,346
    hi and welcome

    source (mark the lower case, linux is case sensitive) is used by e.g. bash to read a bash script.

    But to pass sql statements from a file to mysql you would use something like
    Code:
    mysql < /home/SQL/create-tbl.sql
    mysql < DB_NAME /home/SQL/create-tbl.sql
    MySQL :: MySQL 5.6 Reference Manual :: 4.5.1.5 Executing SQL Statements from a Text File

    Notes:
    - The mysql daemon must be started
    - Your user need to have the correct *mysql* privileges to create/modify a db
    - mysql users are different than system users.
    You must always face the curtain with a bow.

  3. #3
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,184
    Your home directory will be /home/stewart. User directories are always created under /home. The new directory that you created is inside your home directory so it will be /home/stewart/SQL.

    But you don't need to type that in full each time. Did you notice the little squiggle ~ at the end of your bash prompt? That is short for "my home directory". It occurs there to show that your current working directory is your home directory. If you had moved into your SQL sub-directory, you would have seen "~/SQL" as the current working directory. So if you want to refer to it, "~/SQL" will also do. Now compare the three forms you used with the correct forms and you should see at once why they are wrong.

    There are no stupid questions. There are only opportunities to learn, and stupid people who won't learn.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  4. #4
    Just Joined!
    Join Date
    Jan 2013
    Posts
    4
    Quote Originally Posted by hazel View Post
    Your home directory will be /home/stewart. User directories are always created under /home. The new directory that you created is inside your home directory so it will be /home/stewart/SQL.

    But you don't need to type that in full each time. Did you notice the little squiggle ~ at the end of your bash prompt? That is short for "my home directory". It occurs there to show that your current working directory is your home directory. If you had moved into your SQL sub-directory, you would have seen "~/SQL" as the current working directory. So if you want to refer to it, "~/SQL" will also do. Now compare the three forms you used with the correct forms and you should see at once why they are wrong.

    There are no stupid questions. There are only opportunities to learn, and stupid people who won't learn.
    Thanks that worked perfectly and yes it does make more sense now. I still dont know the Linux directory structure, just sort of slowly picking it up

  5. #5
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    620
    "source" is a way for bash (the command line interface) to read bash commands and execute them. I would assume that the the "*.sql' files are for a database and you will have to use the database program to process them. For example if you were using Postgresql the command would be:
    Code:
    psql -f ~/SQL/create-tbl.sql
    
    or
    
    cd 
    psql -f ./SQL/create-tbl.sql
    
    
    or
    
    cd ~/SQL
    psql -f create-tbl.sql
    
    or
    
    cd
    cd SQL
    psql -f create-tbl.sql
    
    and so one
    .

    As for your reference for the file, all three are incorrect, which you would have found out if you would have attempted to use cd to find the path.
    Code:
    cd /
    ls
    You would not see SQL or stewart, but you would have seen home.
    Code:
    cd home
    ls
    You would not see SQL, but you would see steward
    Code:
    cd stewart
    ls
    Here you would see SQL, as you are in your "HOME" directory.

    Here are several ways to reference the HOME directory, such as:
    Code:
    ${HOME}/
    ~/
    I like the "~/" myself as it and and it siblings.
    Code:
    ~penelope/           --- the HOME directory for user "penelope"
    ~/                       --- my HOME directory
    ~-/                      --- the directory I was in just before changing to the current directory
    The use of "~" as a short cut to "HOME" is because when it was adopted, the key that contained the "~" has a shift labeled "HOME" (which was to the beginning of the line). Since usage is hard to change, even though that pairing of the labels are present on the same key the "~" is still used as home.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •