If you possess advanced user skills, you may opt to utilize SSH for accessing and modifying your account, as it provides a more comprehensive range of options with fewer constraints. Familiarity with SSH is essential for this process.
Here are the steps to import your database from the command line:
NOTE: Ensure your database file is in .sql format; compression in .zip or .tar.gz is not permissible.
-
Initially, log in to SSH and upload your database to your home directory. This can be accomplished through cPanel File Manager, an FTP client, or SSH.
-
If the database is not present, create a database, a user, and grant the user complete privileges. Take note of the username and password.
-
Log into your server using SSH.
-
Use the ls -l command to confirm the file's presence in your current directory.
-
If the file is not available, either upload/move it to the correct directory or navigate to the directory where the file is located.
-
Enter the following command, replacing 'user_name,' 'database_name,' and 'file.sql' with your username, database name, and file:
-
mysql -p -u user_name database_name < file.sql
-
You will be prompted for your database user password, and upon successful entry, your database will be imported.
Steps for Command Line Database Export:
-
Launch the command line on the computer where the database is situated. If the database is hosted elsewhere, such as on another web hosting account or with a different provider, use SSH to log in to the respective account. If you have physical access to the computer, open a DOS or terminal window to access the command line.
-
Enter the following command and press Enter. Replace 'username' with your actual username, and 'dbname' with the name of the database you intend to export:
-
mysqldump -u username -p dbname > dbexport.sql
-
Note: The filename 'dbexport.sql' is used in this example for the exported database, but you can choose any desired filename.
-
Provide your password when prompted at the "Enter password" prompt.
-
The 'dbexport.sql' file now contains all the data from the 'dbname' database. If the 'dbexport.sql' file is situated on a remote computer, download it to your local computer.
By following these steps, you can perform both import and export operations for your database via the command line.