[MySQL] Summary of common errors

Table of contents

1. Remote connection MySQL user permission issues

solution

2. MySQL reports an error using the aggregate function group by

Solution one

Solution 2

 3. The server has gone away when MySQL imports data.

Solution one

Solution 2


1. Remote connection MySQL user permission issues

When connecting to MySQL remotely, the prompt is: ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server. This is a problem of not being able to give user permissions for remote connections.

solution

Enter mysql -u root -p password to enter the mysql console and execute the following two statements to connect remotely.

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION; 

flush privileges;

2. MySQL reports an error using the aggregate function group by

On Linux, MySQL reports an error when using the aggregate function group by: SELECT list is not in GROUP BY clause and contains nonaggre

Error reporting example

Expression #2 of SELECT list is not in GROUP BY clause and contains 
nonaggregated column ‘sss.month_id’ which is not functionally 
dependent on columns in GROUP BY clause; this is incompatible with 
sql_mode=only_full_group_by

Problem analysis: MySQL 5.7.5 and above functions depend on the detection function. If ONLY_FULL_GROUP_BY SQL mode is enabled (the default), MySQL will reject queries with select lists, HAVING conditions, or ORDER BY lists that reference non-collection columns that are neither named in the GROUP BY clause nor functionally dependent on them. (Prior to 5.7.5, MySQL did not detect functional dependencies and did not enable ONLY_FULL_GROUP_BY by default. See the MySQL 5.6 Reference Manual for a description of pre-5.7.5 behavior.)

Solution one

1. Open navcat and query with sql:

select @@global.sql_mode

2. Operation results

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

3. Remove ONLY_FULL_GROUP_BY and reset the value.

set @@global.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

However, the above method is only temporary. After restarting mysql, the original mode will be restored and an error will occur.

Solution 2

Remove ONLY_FULL_GROUP_BY in the configuration file /etc/my.cnf or your own mysql configuration file. This method is permanently effective.

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

 3. The server has gone away when MySQL imports data.

Generally, when we import large files, the connection will be disconnected, resulting in such errors.

Cause

  • The MySQL server timeout setting is too short, causing the connection to be disconnected.
  • The imported sql file is too large and the MySQL server cannot process all the data, causing the connection to be disconnected.
  • The MySQL server is out of memory and cannot process the data, causing the connection to be dropped.

Solution one

Modify the timeout setting: Open the Mysql configuration file, find the "[mysqld]" column, and modify the following two parameters below (if there are no these two parameters, you can add them directly)

wait_timeout=600
max_allowed_packet=64M

The parameter values ​​can be modified according to your own needs. Remember to restart mysql after the modification is completed.

Solution 2

When a SQL file is too large, we can avoid the problem of disconnection by splitting it into smaller files and importing them into the database one by one. This can be done using "split" or other similar commands.

Continuously updated ~

Guess you like

Origin blog.csdn.net/qq_25285531/article/details/134026757