Getting Error while importing database in MYSQL

In this article, we will solve the most common error faced by developers while connecting with MYSQL Database.

MySQL ERROR 1046 (3D000) at line 22: No database selected

This is the most common error faced by the developer. Let us see how to solve it. First, let us see when you will face this error. Here, we will use a command-line client.

Consider, an example you want to fetch data from a user table as shown below:

As you can see, we got the ERROR 1046 (3D000): No database selected. Now, we will solve this error.

Solution 1:

Here, in order to fetch any data from the MYSQL table, first, we need to select the database from where we want to fetch data.

mysql> use [database];

Here, instead of [database] write the name of the database. Now, you will get the database changed message. Next, you can fetch any data from this database.

Solution 2:

“No database selected” error means “You are missing the database” and your script is not able to auto-create the database to solve this  Create an empty database into MySQL workbench with the same name and while importing the database file select the project name.

  1. Edit the .sql file and check the database name in the top section of the file.
  2. Create a database into MySQL workbench with the same name.
  3. Now refresh the server(Close the import section if it’s open).
  4. Import the project again and while importing it, select the project name.
  5. Click to Import.

Mysql ERROR 2013 (HY000) at line 143: Lost connection to MySQL server during query

==> SET GLOBAL max_allowed_packet=1073741824;

MySQL server has gone away

Unknown collation: ‘utf8mb4_0900_ai_ci’

You can solve this by finding

ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
in your .sql file, and swapping it with