3

I have just installed MySQL Community Server and now want to create a database and then run a script on it in a command line.

I tried this one but looks like it doesn't work:

CREATE DATABASE admin_web_projektu
mysql admin_web_projektu < c:/USI-4/db_template_001.sql
2
  • and what is not working? Commented Dec 22, 2011 at 9:14
  • make sure you have logged in to mysql on command line Commented Dec 22, 2011 at 9:19

3 Answers 3

3

use below steps:

  1. Create database yourdbname;

  2. use yourdbname;

  3. source path_to_DB_script;

Sign up to request clarification or add additional context in comments.

1 Comment

I tried what you suggested and here is the result: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'src c :/USI-4/db_template_001.sql' at line 1 mysql>
0

try this:

LOAD DATA INFILE 'data.txt' INTO TABLE YourTable

References: read this for more detail http://docs.oracle.com/cd/E17952_01/refman-5.1-en/load-data.html

Comments

0

You need to exit the MySQL console to run your command.

mysql> exit
$ mysql -uroot -ppassword -B database < /path/to/script.sql

The -u indicates user, -p operator indicates the password and -B the database to use. Note that there is no gap between the -p and the password, otherwise MySQL considers the space part of the password. I tend to leave out a space before the username too :) old habits I guess.

The greater and less than operators < and > act as directional indicators for your bash commands. Think of them as 'into'. So the above statement might be stated as follows:

$ database (into) file

If you were dumping the database into a file, your direction would be > toward the file. However, you want to put the file 'into' the database, so the direction is <. Maybe that helps?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.