Как вы запускаете один запрос через MySQL из командной строки?

131
задан Matthew 21 October 2009 в 19:00
поделиться

5 ответов

mysql -u <user> -p -e "select * from schema.table"
220
ответ дан 23 November 2019 в 23:45
поделиться
mysql -uroot -p -hslavedb.mydomain.com mydb_production -e "select * from users;"

From the usage printout:

-e, --execute=name
Execute command and quit. (Disables --force and history file)

22
ответ дан 23 November 2019 в 23:45
поделиться

here's how you can do it with a cool shell trick:

mysql -uroot -p -hslavedb.mydomain.com mydb_production <<< 'select * from users'

'<<<' instructs the shell to take whatever follows it as stdin, similar to piping from echo.

use the -t flag to enable table-format output

10
ответ дан 23 November 2019 в 23:45
поделиться
echo "select * from users;" | mysql -uroot -p -hslavedb.mydomain.com mydb_production
5
ответ дан 23 November 2019 в 23:45
поделиться

If it's a query you run often, you can store it in a file. Then any time you want to run it:

mysql < thefile

(with all the login and database flags of course)

9
ответ дан 23 November 2019 в 23:45
поделиться
Другие вопросы по тегам:

Похожие вопросы: