0

I tried to load code examples from http://examples.oreilly.com/9780596527082/. This approach don't work for me:

error error2 error3 users

Limbs.sql can be found in recipies/tables (this is example from book).

I work on ver. 5.6.24 (localhost) and Windows 7.

Kulis
  • 988
  • 3
  • 11
  • 25

2 Answers2

1

mysql -uroot -pYOUR_PASSWORD test77db < this.sql

no space after -u and -p. A space there can really confuse mysql.

so it looks like mysql -uroot -pYOUR_PASSWORD test77db < this.sql

this runs this.sql against test77db

be careful using root

a better example would be mysql -ujohn -popen_sesame test77db < this.sql

where user is john and password=opensesame

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

follow along below in my make-believe database:

in my example test77db is the database name. so my .sql file does not need to reference the dbname cause you are passing it at shell. but put it in there anyway as a use stmt. i will show u

get into mysql with authorization to create a database, perhaps as root, whatever.

so now you are at a mysql prompt.

example below in database test77db:

use test77db; -- just for kicks to emphasize the point

CREATE TABLE bonehead
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
who_is_bonehead VARCHAR(100) NOT NULL
);

you just created the table, now quit mysql

you are now at an operating system (linux,dos,whatever) prompt

create this.sql text file, it merely contains:

use test77db;

insert into bonehead(who_is_bonehead) values('Drew Pierce');

save it.

then run (you are still at an operating system prompt!)

mysql -uroot -pYOUR_PASSWORD test77db < this.sql

you are now at a mysql prompt, enter

use test77db; -- this is the database name

select * from bonehead;
Drew
  • 24,851
  • 10
  • 43
  • 78
1

There are two ways to execute an external file on your database: 1. From the command line 2. From within the MySQL client

First, to identify which application you are using (The DOS command line, or the MySQL client application), look at your prompt. When you are within the MySQL client, your prompt will say:

    mysql>

You get that window/prompt by double clicking the MySQL client application. This is the prompt I see in your provided screenshots.

If you're in the windows command line, your prompt will say something like:

    C:\Users\kulis>

You get to the Windows Command Line by typing "cmd" in the Windows start menu, or searching for it within the Start menu.

To execute an external script in the MySQL client application (which is where you are in your screenshots), you'll need to use the "source" command:

    mysql> source \path\to\your\script\limbs.sql

Alternately, if you use the Windows Command Line, you can use the command you've already tried:

    c:\Users\kulis>  cd D:\Nauka\SQL\bazy\recipes\tables
    D:\Nauka\SQL\bazy\recipes\tables>  mysql -uroot -pcookbook < limbs.sql

Source: http://dev.mysql.com/doc/refman/5.6/en/mysql-batch-commands.html

Bill
  • 304
  • 1
  • 4