how do I create a database on linux machine running mysql?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MLH

    how do I create a database on linux machine running mysql?

    I have an sql script file that is supposed to create
    a set of database tables for me. Supposedly I type
    the following on my linux box and its all supposed
    to work...

    mysql (ENTER)
    \. mysql_dump.sql. txt

    When I type myslq <ENTER> I get a command prompt
    that looks like this...

    mysql>

    But I don't know how to change directories from that
    command prompt to the directory where mysql_dump.sql. txt
    is located. Can someone tell me how to change dirs at
    the mysql> prompt?
  • Chris Hope

    #2
    Re: how do I create a database on linux machine running mysql?

    MLH wrote:
    [color=blue]
    > I have an sql script file that is supposed to create
    > a set of database tables for me. Supposedly I type
    > the following on my linux box and its all supposed
    > to work...
    >
    > mysql (ENTER)
    > \. mysql_dump.sql. txt
    >
    > When I type myslq <ENTER> I get a command prompt
    > that looks like this...
    >
    > mysql>
    >
    > But I don't know how to change directories from that
    > command prompt to the directory where mysql_dump.sql. txt
    > is located. Can someone tell me how to change dirs at
    > the mysql> prompt?[/color]

    From the command line to load a mysql dump file do this:

    mysql -u [username] -p [database_name] < [filename]
    eg
    mysql -u someuser -p somedb < mysql_dump.sql. txt

    --
    Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

    Comment

    • usaims

      #3
      Re: how do I create a database on linux machine running mysql?

      MLH,
      There is a good book called MySQL written by Paul DuBois, it has
      tutorials and stuff. It seems like you are new to databases from the
      question you asked. I highly recommend you getting the book and learn
      this fun stuff if you have the inclination to absorb this technology.

      usaims

      Comment

      • Bill Karwin

        #4
        Re: how do I create a database on linux machine running mysql?

        usaims wrote:[color=blue]
        > There is a good book called MySQL written by Paul DuBois, it has
        > tutorials and stuff.[/color]

        There's also a MySQL tutorial online at:


        With regards to loading data from the script, there are several choices:

        One option is to cd to the directory before you run the mysql tool:
        $ cd directory/containing/script
        $ mysql
        mysql> source mysql_dump.sql. txt

        Another option is to use the path to the dump file:
        $ mysql
        mysql> source directory/containing/script/mysql_dump.sql. txt

        Another option, as Chris Hope pointed out, is to run the script directly
        from the command line:
        mysql databasename < directory/containing/script/mysql_dump.sql. txt

        (you also might need to specify "-u username" and "-p", if the database
        is configured to require a non-anonymous login and password)

        Regards,
        Bill K.

        Comment

        • Chris Hope

          #5
          Re: how do I create a database on linux machine running mysql?

          Bill Karwin wrote:
          [color=blue]
          > usaims wrote:[color=green]
          >> There is a good book called MySQL written by Paul DuBois, it has
          >> tutorials and stuff.[/color]
          >
          > There's also a MySQL tutorial online at:
          > http://dev.mysql.com/doc/mysql/en/tutorial.html
          >
          > With regards to loading data from the script, there are several
          > choices:
          >
          > One option is to cd to the directory before you run the mysql tool:
          > $ cd directory/containing/script
          > $ mysql
          > mysql> source mysql_dump.sql. txt
          >
          > Another option is to use the path to the dump file:
          > $ mysql
          > mysql> source directory/containing/script/mysql_dump.sql. txt
          >
          > Another option, as Chris Hope pointed out, is to run the script
          > directly from the command line:
          > mysql databasename < directory/containing/script/mysql_dump.sql. txt
          >
          > (you also might need to specify "-u username" and "-p", if the
          > database is configured to require a non-anonymous login and password)[/color]

          I hadn't seen that "source" one from within the mysql command prompt
          before. That's really cool. Thanks Bill.

          --
          Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

          Comment

          • MLH

            #6
            Re: how do I create a database on linux machine running mysql?

            Thank-you for suggesting this syntax...
            mysql databasename < directory/containing/script/mysql_dump.sql. txt
            I tried it. I got an error msg. Here is the error...
            ERROR 1044: Access denied for user: '@localhost' to database
            'mydatabase'

            I was not logged in as root at the time of running the command.
            xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxx
            <snip>[color=blue]
            >
            >Another option, as Chris Hope pointed out, is to run the script directly
            >from the command line:
            > mysql databasename < directory/containing/script/mysql_dump.sql. txt[/color]
            <snip>[color=blue]
            >Regards,
            >Bill K.[/color]

            Comment

            • MLH

              #7
              Re: how do I create a database on linux machine running mysql?

              I tried cd'ing to the directory containing mysql_dump.sql. txt,
              running mysql <ENTER> and finally source mysql_dump.sql. txt.
              A bunch of error messages saying
              ERROR 1046: No Database Selected
              filled up the screen.
              xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxx[color=blue][color=green]
              >>
              >> One option is to cd to the directory before you run the mysql tool:
              >> $ cd directory/containing/script
              >> $ mysql
              >> mysql> source mysql_dump.sql. txt
              >>
              >> Another option is to use the path to the dump file:
              >> $ mysql
              >> mysql> source directory/containing/script/mysql_dump.sql. txt
              >>
              >> Another option, as Chris Hope pointed out, is to run the script
              >> directly from the command line:
              >> mysql databasename < directory/containing/script/mysql_dump.sql. txt
              >>
              >> (you also might need to specify "-u username" and "-p", if the
              >> database is configured to require a non-anonymous login and password)[/color]
              >
              >I hadn't seen that "source" one from within the mysql command prompt
              >before. That's really cool. Thanks Bill.[/color]

              Comment

              • MLH

                #8
                Re: how do I create a database on linux machine running mysql?

                I tried the following syntax
                mysql -u mlh -p mydatabase < mysql_dump.sql. txt
                and received the following error msg...

                ERROR 1045: Access denied for user: 'mlh@localhost' (Using Password:
                YES)

                The mlh user is my non-root linux userID. The recommended syntax
                shown below indicates 'someuser' and mlh is what I used. Also, it
                indicates 'somedb'. I used 'mydatabase' as the name, since I am
                doing this for test purposes now. Since I don't have a database yet
                (running this script is supposed to create one) I assume the name I
                use in place of somedb will be the name of the database that's created
                xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxx
                <snip>[color=blue]
                >
                >From the command line to load a mysql dump file do this:
                >
                >mysql -u [username] -p [database_name] < [filename]
                >eg
                >mysql -u someuser -p somedb < mysql_dump.sql. txt[/color]

                Comment

                Working...