Error Messages;
sqlalchemy.exc.ProgrammingError: (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 'fromt_user' at line 1")
The error message is like this, which means that my SQL syntax is wrong
Today, when pandas was connecting to the MySQL database, there was an error in the last run
Source code:
from sqlalchemy import create_engine
def query(table):
host = 'localhost'
user = 'root'
password = '123456'
database = 'ConstructionDB'
port = 3306
conn = create_engine('mysql+pymysql://{}:{}@{}:{}/{}'.format(user, password, host, port, database))
sql = 'select * from' + table
results = pd.read_sql(sql, conn)
return results
Through debugging, it is found that there is no space in the original SQL statement when it is spliced, resulting in the last syntax of SQL
sql = [select * fromt_user]
Solved it!
def query(table):
host = 'localhost'
user = 'root'
password = '123456'
database = 'ConstructionDB'
port = 3306
conn = create_engine('mysql+pymysql://{}:{}@{}:{}/{}'.format(user, password, host, port, database))
sql = 'select * from' +' ' + table
results = pd.read_sql(sql, conn)
return results
Pay attention to the SQL statement and splice a space in the middle of the code. The problem is solved
Read More:
- [Solved] pymysql.err.ProgrammingError: (1064, ‘You have an error in your SQL syntax;
- [Solved] Pyodbc.ProgrammingError: No results. Previous SQL was not a query.
- pymysql Error: File “/usr/local/lib/python2.7/site-packages/PyMySQL-1.0.2-py2.7.egg/pymysql/connections.py”, line 167 SyntaxError: invalid syntax
- [Solved] pymysql.err.OperationalError: (1045, “Access denied for user ‘root‘@‘192.168.118.44‘
- [Solved] pymysql.err.internalError: (1054, “Unknown column ‘LGD_xiaohong’ in ‘field list’”)
- MySQL Change password failure prompt: ERROR 1064(42000):You have an error in your SQL syntax: check the corresponds to your M
- MYSQL Use cmd to change root password error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual tha
- [Solved] java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corres
- [Solved Perfectly] MySQL ERROR 1064 (42000): You have an error in your SQL syntax;
- Mysql 8.0.13 Enabling remote access (ERROR 1064 (42000): You have an error in your SQL syntax; check the manual th)
- Error 1064 (42000): you have an error in your SQL syntax
- MySQL Build table error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL ser
- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- Bulk Update Error: #Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the m
- [Solved] there are special symbols in the initial password for installing MySQL in Hadoop, and an error is reported
- mysql ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executin
- [Solved] mysqldump: Error: ‘Access denied; you need (at least one of) the PROCESS privilege(s) for this opera
- linux mysql ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
- [Solved] Sqlyog always reports an error when creating a new connection.
- [Solved] C# connecting to MySQL database reports an error