Chaining MySQL commands, Automating database import
Question: I am currently writing a python script to automate my process for installing a
new project on my server.

I simply want to be able to achieve this:

    
    
    use database_name;
    source database_file.sql
    

In one line using the:

    
    
    mysql -e
    

switch.

pseudo code:

    
    
    mysql -uadam -p123456 -e 'use database_name and source database_file.sql'
    

I have tried:

    
    
    mysql -uadam -p123456 -e 'database_name < database_file.sql'
    

The above command throws a syntax error. Any help would be greatly
appreciated.

Ad


Answer: Use this:

    
    
    mysql -uadam -p123456 database_name < database_file.sql
    

You don't need the `-e` switch to import a `.sql` file

