How to log in to MySQL and query the database from Linux terminal?
To log in to a MySQL database and execute queries from the Linux terminal, follow these steps:1. Open the terminalFirst, open your Linux terminal.2. Log in using the MySQL clientIn the terminal, you can log in to the MySQL database using the command with the necessary parameters. The basic command format is as follows:Here, is followed by your MySQL username, and indicates that the command will prompt you for your password. For example, if your username is , you can enter:After entering the command, the system will prompt you for your password. After entering the correct password, you will be logged into the MySQL server.3. Select the databaseAfter logging in, you can use the command to select the database you want to query. For example, if the database name is , you can enter:4. Execute the queryOnce the database is selected, you can execute SQL queries. For example, if you want to view all records in the table, you can use the following command:5. Exit MySQLAfter completing the query, you can exit the MySQL client by entering the command:ExampleSuppose I have a database named with a table named . I want to log in to MySQL from the Linux command line and view all student information. Here are my steps:Open the terminal.Enter , then enter your password.Enter to select the database.Execute the query to view all student data.After completion, enter to exit the MySQL session.Through this process, you can successfully log in to MySQL from the Linux terminal and query the database. This method is very useful for database administrators and developers when managing and debugging databases.