Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell - one line query

Tags:

People also ask

How do I run a query in MySQL shell?

Running select queries After you have logged into a database with the MySQL command line tool (covered in my using the MySQL command line tool post), you can run queries by simply typing them in at the command prompt. The query will not be executed until you either enter ; g or G and then press the <enter> key.

How query MySQL database command line?

To access a specific database, type the following command at the mysql> prompt, replacing dbname with the name of the database that you want to access: Copy use dbname; Make sure you do not forget the semicolon at the end of the statement. After you access a database, you can run SQL queries, list tables, and so on.

How do I run a query in terminal?

To run SQL files from the terminal, you can use the source or the backslash and dot command ( \. ) Next, enter the password for your root user. The path /Users/nsebhastian/Desktop/test/main. sql above needs to be changed to the SQL file path on your computer.


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' < query.file 

But instead of the < query.file it would like to use a raw query like this:

mysql database --user='root' --password='my-password' < UPDATE `database` SET `field1` = '1' WHERE `id` = 1111; 

Is that possible?