1

i found this code but do not quite understand what the command is doing.

sudo -u test-user mysql -U test_traffic traffic < ./phoenix/data/sql/lib.model.schema.sql

i know the last part is using lib.model.schema.sql to create the tables and fields the first part i dont quite understand: sudo -u test-user mysql -U test_traffic traffic

i know the command sudo and mysql

please explain? thanks

6
  • Is database is created and you want to run script for table schema? Commented Feb 16, 2012 at 8:52
  • yes have a database just want to use schema.sql for tables Commented Feb 16, 2012 at 9:03
  • What exactly do you want to do ? Is your goal to inject a SQL file in your DB using a bash script or just to understand what this script does ? Commented Feb 16, 2012 at 9:13
  • If you understand sudo and mysql then what's left to explain? sudo -u switches to another system user (not root) and mysql -U similarly selects a MySQL user name. Commented Feb 16, 2012 at 9:18
  • both what does -U stand for then after that i have the database name = test_traffic and then is "traffic" the host? i run the script with this line and i get: [sudo] password for helloises: mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) using readline 6.1 Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license Usage: mysql [OPTIONS] [database] as if it shows the "help" menu so something aint right with that line, thanks Commented Feb 16, 2012 at 9:21

3 Answers 3

3

Let's look at it bit by bit. Firstly the format

sudo -u username command

is an instruction to run command (which might be simple or complex) as the user username. So in your example, you are running the mysql command as the user test-user. You should note that this includes all the parameters to the mysql command - that's the entire rest of the line.

The command

mysql -U test_traffic traffic < ./phoenix/data/sql/lib.model.schema.sql

appears corrupt (certainly running it on 5.0.51a fails). It would make sense if the -U was a -u which would indicate that that the command was to be executed for mysql user test_traffic. If it was a -u you would then have an instruction to import the sql file into the traffic database.

So the combined instruction says, import the lib.model.schema.sql file into the database test_traffic using the mysql user test_traffic and executing the entire command as if you were logged-in as the user test-user.

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

Comments

2

Try Below steps for mysql:

   mysql > -h hostname  -u username -p password

    mysql > use databasename;

    mysql > source path/to/scriptfile

Comments

2

If you want to inject theschema.sql file into your database, with a shell script, simply use :

mysql -h [host] -u [username] -p[password] -D [database] < your_file

If you want to dynamicly tell which file should be loaded, replace your_file by $1 and pass the name of the file as an argument to your script.

Take care also to the -p option. There is no space between the -p and your password.

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.