MySQL/MariaDB: Run SQL Queries From A Shell Prompt / Command Line

MySQL/MariaDB: Run SQL Queries From A Shell Prompt / Command Line

To run SQL queries from a shell prompt or command line in MySQL or MariaDB, you can use the mysql command-line client. The mysql command-line client allows you to connect to a MySQL or MariaDB server and execute SQL statements from the command line.

Here's an example of how to use the mysql command-line client to connect to a MySQL or MariaDB server and run a SQL query:

refer‮l:ot ‬autturi.com
mysql -u username -p database_name

This will prompt you to enter your password and then connect to the MySQL or MariaDB server and the database specified in the database_name argument. Once connected, you can enter SQL statements at the mysql> prompt.

For example, to run a simple SELECT statement to retrieve all rows from a table called customers, you can use the following command:

mysql> SELECT * FROM customers;

This will execute the SELECT statement and display the results.

By using the mysql command-line client, you can run SQL queries from a shell prompt or command line in MySQL or MariaDB. It's always a good idea to carefully review the documentation and use the appropriate options and syntax when working with the mysql command-line client. This will help ensure that your queries are executed correctly and that any problems are detected and addressed.

Created Time:2017-10-30 10:17:51  Author:lautturi