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.
mysql commandThe 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.To connect to a MySQL server:
mysql -h example.com -u root -pAfter typing this command, you will be asked to enter the password.
Once you have logged in, select a database:
USE database_name;Running SQL queries
Run SQL queries. For example
SELECT * FROM table_name;To import a database from a SQL file :
mysql -h example.com -u [user] -p [database_name] < file.sqlExporting a database
To export a database to a SQL file, use mysqldump:
mysqldump -h example.com -u [user] -p [database_name] > backup.sqlYou can run an SQL command directly from the command line:
mysql -h example.com -u [user] -p -e "SHOW DATABASES;"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.
You now know how to :
mysql command to connect to your database.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! 💬🙌
Ask the LWS team and the community. Answers are published after moderation.