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

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:

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:

USE database_name;

Running SQL queries

Run SQL queries. For example

SELECT * FROM table_name;

Importing and exporting databases

Importing a database

To import a database from a SQL file :

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

Exporting a database

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

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:

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:

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! 💬🙌

Rate this article :

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problÚme technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

1mn reading

How do I connect to the Web Terminal with LWS Panel? (ssh web console)

4mn reading

How can I use GIT with the Web terminal on my LWS shared hosting?

2mn reading

How to change the PHP version of the LWS Panel Web Terminal

0mn reading

What can I do on my WordPress site using the Web Terminal?


Ask the LWS team and its community a question