Category Archives: MYSQL

MySQL database insert into statement with parameters Error

When using MySQL insert statement, I suddenly found that when inserting non numeric parameters, the database will report an error

mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column '2ddd22' in 'field list'

Cloumn is followed by the parameter to be inserted

import mysql.connector
 
class MysqlGroup(object):
    def __init__(self,host,user,password,database,charset):
        self.mydb=mysql.connector.connect(host = host,user = user,port = 3306,password = password,database = database,charset = charset,buffered = True)
        self.mycursor=self.mydb.cursor(buffered = True)
    
    def mysql_increase(self, surface_name, column_name1, column_name2, parameter1, parameter2):  
        self.mycursor.execute(
            "INSERT INTO %s (%s, %s) VALUES (%s, %s)" % (surface_name,column_name1, column_name2, parameter1, parameter2))
        self.mydb.commit()
 
                               
con1 = MysqlGroup('database address', 'database username', 'database password', 'database name', 'encoding method')    
jk = con1.mysql_increase('data','user', 'password','2ddd22','3333')

The reason for the error is that the database incorrectly identifies the value to be inserted as a column name
The solution is to add single quotes’ to both sides of the value to be inserted in the SQL statement, with the following code.
import mysql.connector

class MysqlGroup(object):
def __init__(self,host,user,password,database,charset):
self.mydb=mysql.connector.connect(host = host,user = user,port = 3306,password = password,database = database,charset = charset,buffered = True)
self.mycursor=self.mydb.cursor(buffered = True)

def mysql_increase(self, surface_name, column_name1, column_name2, parameter1, parameter2):
self.mycursor.execute(
“INSERT INTO %s (%s, %s) VALUES (‘%s’, ‘%s’)” % (surface_name,column_name1, column_name2, parameter1, parameter2))
self.mydb.commit()

con1 = MysqlGroup(‘database address’, ‘database username’, ‘database password’, ‘database name’, ‘encoding method’)
jk = con1.mysql_increase(‘data’,’user’, ‘password’,’2ddd22′,’3333′)
Disadvantage, after adding single quotes, the SQL statement will not recognize the keyword like Null and will treat it as a character. To use keywords, you need to write the SQL statement directly. For example:
import mysql.connector

class MysqlGroup(object):
def __init__(self,host,user,password,database,charset):
self.mydb=mysql.connector.connect(host = host,user = user,port = 3306,password = password,database = database,charset = charset,buffered = True)
self.mycursor=self.mydb.cursor(buffered = True)

def mysql_insert_null(self, surface_name, column_name1, column_name2):
self.mycursor.execute(
“INSERT INTO %s (%s, %s) VALUES (Null, Null)” % (surface_name,column_name1, column_name2))
self.mydb.commit()

con1 = MysqlGroup(‘database address’, ‘database username’, ‘database password’, ‘database name’, ‘encoding method’)
jk = con1.mysql_increase(‘data’,’user’, ‘password’)
Insert null values into the user and password columns of the data table

PHP Connect MYSQL8.0 Error: Server sent charset unknown to the client. Please, report to the developers

Server sent charset unknown to the client. Please, report to the developers

[questions]

Connect the lower version of PHP to the higher version of MySQL (such as mysql8.0)

Server sent charset unknown to the client. Please, report to the developers

[solution]

Method (1): upgrade the PHP connection driver

Method (2): put mysql8.0   Change the parameter of character_set_server to utf8 (it cannot be changed online. You need to modify my.cnf and restart Mysql to take effect)

[Solved] MYSQL add foreign key error: Referencing column ‘xx’ and referenced column ‘xx’ in foreign key constraint ‘xxx’ are incompatible.

Problem Description:

After the migration file is generated, the migration is performed, and the following error occurs:

django.db.utils.OperationalError: (3780,Referencing column ‘category_id’ and referenced column ‘id’   in foreign key constraint ‘tb_goods_visit_category_id_b3e36237_fk_tb_goods_category_id’ are incompatible.)

Question translation:

In the foreign key constraint ‘tb_goods_visit_category_id_b3e36237_fk_tb_goods_category_id’, the reference column ‘category_id’ and the reference column ‘ID’ are incompatible.

Cause analysis:

It is as like as two peas, which are inconsistent with the two data types. For example, varchar and int, or int, unsigned and int are not allowed.

My error is reported because the “category_id” in table a is bigint and the “Id” in table B is int. they are inconsistent.

Solution:

Modify the types of the related two columns in the associated two tables to be consistent, then you can add foreign keys, and then migrate the data successfully.

Oneinstack Backup Database Error: ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

 

Error Message:

Error: ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

 

Solution:

Open the my.ini file in the MySQL directory, add a line skip grant tables after [mysqld] of the file, save and close the file (in Linux)  /etc/my.cnf)

Linux environment installation MYSQL Error: Redirecting to /bin/systemctl start mysqld.service Failed to start mysqld.service: Unit not found.

Use service mysqld start to start MySQL in centos7 with an error:

Before mentioning this error, let’s first mention the development and current background of MySQL:

MySQL is an open source relational database management system (RDBMS), which uses the most commonly used database management language – Structured Query Language (SQL) for database management
MySQL is open source, so anyone can download it under the license of the general public license and modify it according to personalized needs
MySQL was acquired by sun on January 16, 2008. Since then, as sun was acquired by Oracle, the ownership of MySQL also fell into Oracle’s hands
next, we will mention a new database, MariaDB:

MariaDB database management system is a branch of MySQL, which is mainly maintained by the open source community. The purpose of adopting GPL license is to be fully compatible with MySQL, including API and command line, so that it can easily become a substitute for MySQL
the MariaDB database was developed by the founder of MySQL.

Here’s how to uninstall MariaDB and install MySQL:

View the list of installed MariaDB:
RPM – QA | grep MariaDB

Uninstall all installed MariaDB (according to your own MariaDB list):
RPM – E — nodeps mariadb-libs-5.5.64-1.el7.x86_ 64
rpm -e –nodeps mariadb-5.5.64-1.el7.x86_ 64
rpm -e –nodeps mariadb-server-5.5.64-1.el7.x86_ 64
rpm -e –nodeps mariadb-devel-5.5.64-1.el7.x86_ 64

check the installed MariaDB list again and ensure that all are uninstalled:
RPM – QA | grep MariaDB

download the repo source of MySQL: (version 5.6)
WGet http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

Errors may occur: – bash: WGet: if the command is not found, execute the installation WGet. If the error is not reported, do not execute:

Yum – y install WGet

install mysql-community-release-el7-5.noarch.rpm
sudo RPM – IVH mysql-community-release-el7-5.noarch.rpm

install MySQL
sudo Yum install MySQL server

wait for the installation to complete

service mysqld start

View the current MySQL status

Saved MySQL that I haven’t installed successfully for many days

Navicat Import Datas Error: — 1153 – Got a packet bigger than ‘max_allowed_packet’ bytes

Error in importing MySQL database from Navicat — 1153 – got a packet bigger than ‘Max_allowed_packet’ bytes

After checking, it turns out that the data table exceeds the maximum value of SQL file read and executed by MySQL by default; The maximum is 16m. My SQL file is 200m, so it cannot be executed

Solution:

Find the file my.cnf in the MySQL installation directory, search [mysqld], and add a sentence below it

max_allowed_packet=400M

Restart MySQL service

This size is set according to the size of your SQL file

Docker Run MYSQL Container Error: [ERROR] –initialize specified but the data directory has files in it. Aborting.

background

Start the MySQL container by running the local MAC docker

docker run -d -p 3306:3306 --name mysql1 -v /Users/polo/data/conf:/etc/mysql/conf.d -v /Users/polo/data/mysql:/var/lib/mysql  -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

phenomenon

Check the container log and find that an error is reported, and the local Navicat cannot be connected

Root cause

Files already exist in the directory mounted through – V, so when – V selects the local directory, remember to select an empty directory/nonexistent directory (it will be created automatically)

Solution

Reference links for problem solving

Replace the -v mounted local directory with an empty directory/nonexistent directory

Start the log of MySQL container normally

No error log

Sqoop Import MYSQL Datas to Hive Error: Could not load org.apache.hadoop.hive.conf.HiveConf. Make sure HIVE_CONF_DIR is set correctly

Problem description

Using sqoop to import data from Mysql to hive, an error is reported: could not load org.apache.hadoop.hive.conf.hiveconf. Make sure hive_CONF_DIR is set correctly

analysis

The hiveconf. Class class class exists

measures

Modify $sqoop_HOME/conf/sqoop-env.sh

# Add the content below
export HADOOP_CLASSPATH=/opt/software/hadoop-3.1.3/lib/*:/opt/software/hive-3.1.2/lib/*

Outcome: