Execute sql query from sql file

后端 未结 4 868
野的像风
野的像风 2021-01-07 10:09

I want to include all tables from a database \"shop\" to mydatabase newshop. I export that \"shop\" database, and now it is named as shop.sql. Is t

4条回答
  •  执笔经年
    2021-01-07 11:06

    I think what you need might be:

    $ mysql -u $USERNAME -p < "$SQLFILENAME"

    Where $USERNAME is the user name of mysql like root and $SQLFILENAME is the name of the sql file ('shop.sql' in this case).

    The above command will ask you to type in password. If you don't want to do that every time, you can use '--password=$PASSWORD' BUT be careful. This password may be saved in history and it might be in the wrong hand (If you run it from PHP, it may not be a problem).

    OR you can use mysqli to run it.

    
    

    Hope this helps.

提交回复
热议问题