장 - 세바스티앙 :
나는 구름에있는 기존 테이블을 가지고 있고 나는 그것의 복사본을 만들고 싶어. 나는 pymysql를 통해 내 데이터베이스에 연결할 새 사용자로부터 제공되는 입력에서 사용자 이름을 추출, 그리고 사용자 이름에 의해 호출 될 새 테이블을 만들려면, 그 테이블은 원래의 사본이 될 것입니다. 나는 아래의 코드를 실행하면, 나는 다음과 같은 오류가 있습니다 :
pymysql.err.ProgrammingError: (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 ''username' AS SELECT * FROM original_table' at line 1")
uname = [email protected]
conn = pymysql.connect(
host="db.host",
port=int(3306),
user=user,
passwd=password,
db=db,
charset='utf8mb4'
)
cur = conn.cursor()
table_name = uname.replace('@', '_').replace('.', '_')
print('TABLE NAME:', table_name)
cur.execute(""" CREATE TABLE %s AS SELECT * FROM original_table """, (table_name))
snakecharmerb :
인용 매개 변수 인용을위한 값을 . 테이블 이름을 인용하는 MySQL의에서 방법 (`)가 아닌 인용 부호를 역 따옴표를 사용하는 것입니다 때문에 테이블 이름을 인용하는 것은,하지 작업을 수행합니다.
MariaDB [test]> CREATE TABLE 'username' AS SELECT * FROM my_table;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''username' AS SELECT * FROM my_table' at line 1
이 원인에서 당신은 (당신이 SQL 인젝션 방어 역 따옴표를 사용할 수있는 SQL 문을 작성하는 서식을 사용하여 문자열로 필요 * ) :
cur.execute(""" CREATE TABLE `%s` AS SELECT * FROM original_table """ % table_name)
* 나는 그렇다면 어떤 연구를 수행 SQL 주입에 대한 전문가가 아니에요 table_name
응용 프로그램 외부에서 유래합니다.