Shell - one line query

前端 未结 6 1536
天命终不由人
天命终不由人 2021-02-07 02:01

I need to execute a mysql query in one line using bash.

It should be something like this:

mysql database --user=\'root\' --password=\'my-password\' <          


        
6条回答
  •  日久生厌
    2021-02-07 02:09

    If you are running this on a production environment, it would be better to login to the mysql shell first so as not to expose your db details.

    Once logged into shell, why not just use a prepared.sql file?

    mysql -u user -p

    Next, enter your user password

    Now you are logged into shell and you can run commands securely from here:

    mysql> use DBNAME mysql> SOURCE file.sql

    This is how I operate on the command line with my databases in order for my passwords not to appear in the logs.

提交回复
热议问题