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.
- Edit the .sql file and check the database name in the top section of the file.
- Create a database into MySQL workbench with the same name.
- Now refresh the server(Close the import section if it’s open).
- Import the project again and while importing it, select the project name.
- 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_unicode_ci’
You can solve this by finding
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
in your .sql file, and swapping it with
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
The auto database creates the command
CREATE DATABASE /*!32312 IF NOT EXISTS*/`policy-provider-portal` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */ /*!80016 DEFAULT ENCRYPTION='N' */; USE `policy-provider-portal`;
Solve MYSQL connection time zone error
String url = "jdbc:mysql://localhost/mydb?useLegacyDatetimeCode=false&serverTimezone=America/New_York";
Packet for query is too large (284,510,008 > 67,108,864). You can change this value on the server by setting the ‘max_allowed_packet’ variable.
SET GLOBAL max_allowed_packet = 1024*1024*14;
incompatible with sql_mode=only_full_group_by
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));