How can I use the Web Terminal to act on the SQL service?

Procédure

Using the command line web terminal to import or export databases and perform SQL queries is essential for database developers and administrators.

This documentation explains how to do this.

Prior to this documentation, we invite you to access your hosting's Web Terminal.

Using the mysql command

The mysql command is a command line tool used to interact with the MySQL database server. It allows users to connect to a database, execute SQL queries and manage databases.

General syntax

⌨ Command
mysql -h [host] -u [user] -p
  • -h [host]: specifies the host (server) address. The default is localhost.
  • -u [user]: specifies the user name for the connection.
  • -p: requests the user's password.

Basic commands

Connecting to MySQL

To connect to a MySQL server:

⌨ Command
mysql -h example.com -u root -p

After typing this command, you will be asked to enter the password.

Selecting a database

Once you have logged in, select a database:

⌨ Command
USE database_name;

Running SQL queries

Run SQL queries. For example

⌨ Command
SELECT * FROM table_name;

Importing and exporting databases

Importing a database

To import a database from a SQL file :

⌨ Command
mysql -h example.com -u [user] -p [database_name] < file.sql

Exporting a database

To export a database to a SQL file, use mysqldump:

⌨ Command
mysqldump -h example.com -u [user] -p [database_name] > backup.sql

Executing SQL commands directly from the command line

You can run an SQL command directly from the command line:

⌨ Command
mysql -h example.com -u [user] -p -e "SHOW DATABASES;"

Full example

Here's a complete example of how to connect, select a database, run a query and exit:

⌨ Command
mysql -h example.com -u root -p Enter password: ******** mysql> USE my_database; mysql> SELECT * FROM my_table; mysql> EXIT;

This guide covers the basic operations you can perform with the mysql command, enabling you to manage your MySQL databases efficiently.

Conclusion

You now know how to :

  • Access your hosting's Web Terminal.
  • Use the mysql command to connect to your database.
  • Run basic commands, including selecting a database and executing SQL queries.
  • Import and export databases using specific commands.
  • Execute SQL commands directly from the command line to manage your data quickly and efficiently.

Whether for day-to-day management or one-off tasks, mastering these commands will enable you to navigate the world of MySQL databases with ease. 🚀👨‍💻

Thank you for following us so far! If you have any questions, tips to share, or simply send in your feedback, please feel free to leave a comment below. Your input is valuable to us and to the community! 💬🙌

help.lws.net/a/1910
Was this article helpful?

Yes

No

Read 10 120 times

Thank you! Feel free to ask questions about our documentation if you would like more information, and help us improve it.

Similar articles

A question about this article?

Ask the LWS team and the community. Answers are published after moderation.

Ask the LWS team and its community a question

GDPR: Controller: LWS-Ligne Web Services. Purpose: moderation and public publication of your question, possible notification of an answer. Legal basis: consent (Art. 6(1)(a) GDPR). Email retention: 90 days after notification, 12 months maximum without an answer. To exercise your rights, see the GDPR section of our Terms and Conditions.