Tag Archives: mysql

Solution of MySQL data garbled problem

MySQL data garbled to solve the problem
Note for INSERT
The size of the data should be within the specified range of the column. For example, a string with master 80 cannot be inserted into a column with master 40. The data position listed in VALUES must correspond to the permutation position of the column to be added. You can use value in MySQL, but it is not recommended. It has the same function as values. Character and date data should be enclosed in single quotes. Double quotation marks can also be used as delimiters in MySQL. No column is specified or NULL is used to insert a null value.
View the encoding of MySQL’s internal Settings

show variables like 'character%';

The solution
Change the code of Client, Connection and Results to GBK to ensure that it is consistent with DOS command line code

tr> <>> set cha>er_set_connection = GBK; Set character_set_results= GBKtr> <>> set cha>er_set_results = GBK;

set

description

set GBK character_set_client =; Set character_set_connection= GBK
modify the results of the query character set GBK
Set all three at once

 set names gbk; 

Note: Exit DOS command line is invalid, need to configure each time

Spoop export hive to MySQL

SQOOP Export: mysql> create a Hive table (????)
Like this:

 
I have modified it once before, and the method works together. However, when the server is changed and the MySQL library is newly created, method one fails to work, and method two takes effect.
 
Method one:
Create a new query window, or use the command to enter mysql> , the input

set character_set_database=utf8;
set character_set_server=utf8;

Show variables like ‘character%’; View the results:

SQOOP script with:?useUnicode=true& characterEncoding=utf-8
Import the data again without scrambling.
 
Method 2:
Modify the system file: /etc/my.cnf

vim /etc/my.cnf


Text:

init_connect=’SET collation_connection = utf8_unicode_ci’
init_connect=’SET NAMES utf8′
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

 
 
 
 
Directing to /bin/systemctl Restart mysqld. Service (1) : Directing to /bin/systemctl Restart mysqld.
Sqoop plus?useUnicode=true& CharacterEncoding = UTF-8, Chinese garbled code problem resolved.
 
In the first method, the set modifies the configuration and restarts MySQL. This is probably the first reason why the configuration change does not work.
 
 

Top35: pychar reports an error when connecting to MySQL server returns invalid timezone. Need to set ‘servertimezone’ property

Top35: Server returns invalid timezone. Need to set ‘ServerTimezone’ property.
Error content error cause solution

Content of the error

Error reason

Server returns invalid timezone. Need to set ‘ServerTimezone’ property.
The server returning an invalid time zone needs to set the ‘ServerTimeZone’ property.
reasons: MySQL driver jar package the default time zone was UTC
the UTC is the representative of a global standard time, but we use time is Beijing time zone that is east eight area, UTC eight hours ahead.
The solution
Joining together?ServerTimeZon =UTC

The problem of master-slave database synchronization stop caused by MySQL deleting data

Mysql master database deletes data from the database if not synchronized to delete the data before the synchronization action stops below for the solution
The first step is to stop slave synchronization service.
Step 2: Skip the current error
set global sql_slave_skip_counter=10; (Increase the value if the data is deleted)
Step 3: Start Slave;

Group by query only_ FULL_ GROUP_ By error

The ONLY_FULL_GROUP_BY error in the Group by query

The initial version of mysql for Windows (5.7.28) was used in the project, but later when migrating to Linux, some SQL queries experienced the error ONLY_FULL_GROUP_BY, because MySQL5.7 default set mysql SQL_mode = ONLY_FULL_GROUP_BY attribute, which caused an error (Windows version has no default).
MySQL also provides an any_value() function to suppress ONLY_FULL_GROUP_BY if the business must use a non-grouped field

PHP – PHP Error[2]: Error while sending QUERY packet. PID=*

In the company project today, such an error occurred when yiIC was used to run the database write operation, as shown in the figure below:

Project Scenario:
A big insert SQL and format for the insert INTO the TABLE VALUES (‘ A ‘, ‘B’, ‘C’), (‘ A ‘, ‘B’, ‘C’), (‘ A ‘, ‘B’, ‘C’)…
Code snippet:

It turns out that MySQL’s max_allowed_packet is too small.

The default max_allowed_packet is only 16M, which will occur if the SQL exceeds the set size.
Solutions:
1) Modify the MySQL configuration file
Edit my.cnf (My.ini under Windows) in the [mySQld] section or the server configuration section of mysql
Max_allowed_packet = 50M (or max_allowed_packet = 50*1024*1024)
2) Command line modification
set global max_allowed_packet = 50*1024*1024

Solution to 1030 got error 28 from storage engine in MySQL

Problem Performance:

Solutions:

Mysql 1030 error does not have enough space, so clean up the disk space and restore normal use.

Mysql database had “Got error 28 from Storage Engine” error, so the problem was solved in this way.
1.

XML/HTML code

    disk temporary space is not enough. Solution: empty the/TMP directory, or change the tmpdir parameter in my.cnf to point to the directory with enough space

2,

XML/HTML code

    mysql> ERROR 1030 (HY000): Got ERROR 28 from storage engine
    the reason for this problem: there is not enough temporary space to execute this SQL statement solution: simply point tmpdir to a directory with a large hard disk space

Of course, both statements are the same. So there’s almost certainly no space left. I looked at the other disks and sure enough.

depressed, the backup file was deleted first normal.

An error 1064 is reported when pymysql accesses the image

An error has been reported while accessing images in the mysql database using Pymysql. The code is as follows
Error message: (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00′ at line 1”)
I found a lot of methods on the Internet, but I couldn’t solve the problem. Later, I tried again and again and finally solved it
Note that the size of the binary BLOB in mysql is smaller than the size of the binary BLOB when designing a table, change the binary data to mediumBLOB
The code is as follows:
import pymysql
from datetime import datetime
To create the database, first connect to the mysql database
Conn = Pymysql.connect (host=’127.0.0.1′, user=’root’, Database =’ smart_apartment_DB ‘,
password=’160507pcsd’, charset=’utf8′)
Create a cursor
cursor = conn.cursor()
The # ExCute () function can execute simple SQL statements
f = open(file=’./img/imageOne.jpg’, mode=’rb’)
dataimg = f.read()
f.close()
nowtime = datetime.now().strftime(“%Y-%m-%d, %H:%M:%S”)
argdata = pymysql.Binary(dataimg)
sqlone = “insert into img_pack(imgtime,imgdata) values(‘%s’,’%s’)” % (
nowtime, argdata)
try:
cursor.execute(sqlone)
conn.commit()
except Exception as e:
conn.rollback()
Print (” Error message: “, e)
Close the cursor first
cursor.close()
Close the database connection again
conn.close()
 
After many attempts, the problem was found
sqlone = “insert into img_pack(imgtime,imgdata) values(‘%s’,’%s’)” % (
Remove the ‘%s’ single quotation mark from nowtime, argdata and change to
sqlone = “insert into img_pack(imgtime,imgdata) values(%s,%s)”
Cursor. Execute (SQlone) changed to CURSOR. Execute (SQlone, (nowtime, argdata))
You can store images in a binary stream like mysql
The correct code is as follows
import pymysql
from datetime import datetime
 
To create the database, first connect to the mysql database
Conn = Pymysql.connect (host=’127.0.0.1′, user=’root’, Database =’ smart_apartment_DB ‘,
password=’160507pcsd’, charset=’utf8′)
Create a cursor
cursor = conn.cursor()
The # ExCute () function can execute simple SQL statements
 
f = open(file=’./img/imageOne.jpg’, mode=’rb’)
dataimg = f.read()
f.close()
nowtime = datetime.now().strftime(“%Y-%m-%d, %H:%M:%S”)
argdata = pymysql.Binary(dataimg)
 
sqlone = “insert into img_pack(imgtime,imgdata) values(%s,%s)”
 
try:
cursor.execute(sqlone, (
nowtime, argdata)
)
conn.commit()
except Exception as e:
conn.rollback()
Print (” Error message: “, e)
 
 
Close the cursor first
cursor.close()
Close the database connection again
conn.close()

Error 1051 (42s02): unknown table ‘…’

The reason Why I reported this error is that the storage engine used MyISAM before, but changed to InnoDB later
But I can’t delete the table because the storage engine mode used for the table before is still MyISAM, so I can’t delete it.
1 species,
Modify the storage engine of the table:
The second,
1. Delete the file of the corresponding table. Make sure the table is useless before deleting.
2. Find the location of the corresponding library in the system, such as: /var/lib/mysql/ library name

MySQL:ERROR 1067 (42000): Invalid default value for ‘end_time’

1. Wrong screenshot

2. Error analysis
The first TIMESTAMP column in the table (if not declared NULL or if the DEFAULT or ON UPDATE clause is displayed) automatically assigns the DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP properties
The TIMESTAMP column after the first (if it is not declared NULL or the DEFAULT clause is displayed) automatically allocates DEFAULT ‘0000-00-00 00:00:00’ (zero TIMESTAMP), which does not satisfy the NO_ZERO_DATE in SQL_mode and gives an error.
Note: THERE are two types of SQL_mode, one is null value, the other is strict mode, and many default Settings will be given. Strict mode is used by default after MySQL5.7.
NO_ZERO_DATE: If this value is set, the MySQL database does not allow insertion of a zero date, which throws an error rather than a warning.
3. Solutions
First, execute select @@sql_mode, copy the value of the query and delete the NO_ZERO_DATE, then execute set SQL_mode = ‘modified value’.
This method takes effect only in the current session
Select @@glob.sql_mode, copy the value of the query and delete the NO_ZERO_DATE, then execute set global SQL_mode = ‘modified value’.
This method takes effect in the current service and expires after the MySQL service is re-run
Sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,
Then restart mysql.
This method is permanent