1

I created a table in MYSQL using a shell script shown below in which the attributes are pre-defined.

dbstring="mysql -usample -psample12 -Dsampledb -h127.0.0.1 -A "

echo "CREATE TABLE info (id bigint(20) NOT NULL,email varchar(128) NOT NULL,
createddate datetime DEFAULT NULL)" >> create_table.sql


$dbstring  < create_table.sql

But the thing is i wanted a script that takes the number of attributes as input and takes each attribute at run-time and creates the table in my MYSQL database with those specified attributes.

2
  • And you've tried and failed with... what? Commented Nov 11, 2013 at 13:14
  • I failed with the second part in which the attributes should be taken at run-time and should be inserted in the table. Help me out with that. Commented Nov 11, 2013 at 14:43

1 Answer 1

3

A simple example of a script which takes two parameters and juggles them into an SQL-statement to be fed to mysql. Obviously this is the idea in theory, you should adjust appropriately mysql switches and so on.

#!/bin/sh
cat << EOF | mysql mydatabase
CREATE TABLE info (id bigint NOT NULL, $1 varchar(128), $2 varchar(128));
EOF
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.