0

I want to import into mysql from a script.

Can I do it like this: mysql -u username -p password dbname < employee.sql

If i leave the password out in the command will work, I just have to enter the password after entering the command.

Since I am looking to do it from a script I was hoping to do mysql -u username -p password dbname < employee.sql including the password. Can anyone advise if this is the way to do this or am I completely wrong?

employee.sql look like this:

CREATE TABLE IF NOT EXISTS xyz (
 id int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
 employee_name varchar(255) NOT NULL COMMENT 'employee name',
 employee_salary double NOT NULL COMMENT 'employee salary',
 employee_age int(11) NOT NULL COMMENT 'employee age',
 PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='datatable demo table' AUTO_INCREMENT=64 ;
---- have to change it as above not working -- the below works -- might be different when reading in from file??
INSERT INTO xyz (id, employee_name, employee_salary, employee_age) VALUES
(1, 'Tiger Nixon', 320800, 61),
(2, 'Garrett Winters', 170750, 63),
(3, 'Ashton Cox', 86000, 66),
(4, 'Cedric Kelly', 433060, 22),
...
(56, 'Michael Bruce', 183000, 29),
(57, 'Donna Snider', 112000, 27);
asked May 9, 2016 at 0:09
1
  • think my answer is here, done have a space after -p. I done mysql -u username-p12345 database < employee.sql Commented May 9, 2016 at 2:01

1 Answer 1

2

You don't want a space between -p and the password. so it should be

mysql -u username -ppassword dbname < employee.sql
answered May 9, 2016 at 2:01

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.