MySQL Import
How a MySQL database is imported?
Once a new database has been established in cPanel, you may use the MySQL command-line software or phpMyAdmin to import the contents of the database. You must delete or comment out any CREATE DATABASE lines in the exported database file. The import procedure will not succeed otherwise.
Database export and import in MySQL is moving data from one place to another. Export and import are valuable techniques for transferring data between versions or backing up important info. For instance, our contact book database is vital for our business. It is necessary to keep it in a secure place. So we need to export it to a safe place. Additionally, we may use import options to recover it anytime it is lost from its original location.
There are two basic methods that we may use to export and import databases in MySQL:
- Command Line Tool
- MySQL Workbench
Method #1: use phpMyAdmin
- The phpMyAdmin web interface may be used to import a MySQL database. Follow these steps to do this:
- Get into cPanel. Please refer to this post if you are unsure how to access your cPanel account. Click the phpMyAdmin icon under the DATABASES area of the cPanel home page.
- Open in a new window is the phpMyAdmin management page.
- Click the database to import the data into the phpMyAdmin page's left pane.
- On the Import tab, click. Choose the local copy of the dbexport.
- SQL file by clicking Browse under File to Import. Select "Go".
- Everything imports and runs. At this point, the information found in the dbexport.sql file ought to be in the database.
Method #2: Make use of the MySQL software
- The MySQL application lets you import a database from the command line. Take these actions to accomplish this:
- Use SCP, SFTP, or FTP to move the file named dbexport.sql to your A2 Hosting instance.
- Use SSH to access your A2 Hosting account.
- Navigate to the directory where the dbexport.sql file was uploaded. For instance, use cd ~ to access your home directory if you uploaded the dbexport.sql file.
- Enter the command by typing it in and hitting Enter. Substitute your username for username and the name of the database you want to import the data into for dbname.
MySQL -u username -p dbname < dbexport.sql
- The information in the dbexport.sql file should now be in the name database.
Correcting a MySQL database import
When using phpMyAdmin or the MySQL program to import a MySQL database, you may get one of the following error messages:
- The database 'username2_database' cannot be accessed by user 'username1'@'localhost' due to an error (1044).
- An error message appears when an SQL statement in the import file attempts to access a database using the wrong username. Notice that username2 in username2_database and username1 in 'username1'@'localhost' do not match. To utilize your new username, update the import file and modify username2.
- 'username_database' is an unknown database, according to error 1049.
- This error message is a consequence of the target database not existing. Before importing the database again, ensure you constructed it according to the previous instructions.
- ERROR 1064: You have a syntax error in your SQL; find the right syntax to use at line x, near 'username_database', by consulting the handbook corresponding to your MySQL server version.
- This error notification is shown when a file has a MySQL syntax error or the import file lacks database backup data. The import file might also be altered, corrupted, or in an invalid format. (SQL statements are necessary for importing files; the MySQL program is incompatible with CSV and other file formats.) Try exporting the database again before trying to import it.
- ERROR 1227: Access restricted; you must have (at least) one SUPER privilege to finish this activity.
- An error message appears if the import file contains one or more SQL statements (such as SET GLOBAL or CREATE DEFINER commands) that need superuser permissions. Sometimes, all that has to be done is restart the import process after deleting these lines from the .sql file.
- For example, you may safely remove the CREATE DATABASE instructions since you should have constructed the database in cPanel beforehand. However, you might think about moving. You may transfer your account to a VPS or dedicated server where you can control the settings if you desire MySQL superuser access.
Summary
An essential ability for anybody dealing with databases is the ability to import databases into MySQL. A successful import depends on knowing the procedure and adhering to best practices, whether using graphical interfaces like MySQL Workbench or command-line tools like MySQL. Regularly practising these methods and being updated about new features in MySQL will help ensure dependable and effective database maintenance.