How to Send Sql Queries to Mysql from the Command Line
Method 1 of 1:
Running without the console.
- Find the mysql program (Should be in a subdirectory called bin under the directory where MySQL was installed)
- E.g. Windows users: C:mysqlbinmysql.exe
- E.g. Linux/Unix users: /usr/local/mysql/bin/mysql
- Start mysql - At the command prompt, type: mysql -h hostname -u username -p db_name -e "query"
- where
- host is the machine where the MySQL server is running
- username is the MySQL account you want to use
- -p will make mysql prompt you for the MySQL account password.
- db_name is the name of the database to run the query in, and,
- query is the query that you want to run.
- where
- Enter your password when prompted.
- MySQL should return the result of your query.
4 ★ | 1 Vote
You should read it
- 5 best SQL query optimization software to speed up MySQL
- Instructions for installing MySQL on Windows and remote access
- Backup and restore MySQL with mysql-zrm on Debian Sarge
- The multiple-choice question set has an answer to Query P1
- How to install MySQL on Ubuntu 20.04
- How to install and configure MySQL server on Pi
- How to Connect to MySQL Using PHP
- Action Query in Action 2016
May be interested
- 5 best SQL query optimization software to speed up MySQLthe sql query optimizer analyzes many options for a given query, estimates the cost of each of these options, and finally, selects the lowest cost option.
- TRUNCATE TABLE statement in SQLthe truncate table statement is used to completely delete records from an existing table in sql.
- HAVING clause in SQLthe having clause in sql is used to filter records and retrieve only those records that match the requirements or are actually needed.
- The clause combines UNION data in SQLin sql, you can combine the same structured data from multiple tables into one query using the union and union all operators.
- Frame view VIEW in SQLin sql, a view view is a virtual table in a database whose content is defined through a certain sql statement.
- TRANSACTION in SQLa transaction is successfully performed when all commands are successful, then all data changes made in the transaction are saved to the database.