October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Fix MySQL Error 1064 (SQL Syntax Error)

A practical, version-aware guide to diagnosing MySQL Error 1064, from the near fragment and reserved words to SQL mode, quoting, generated SQL, and minimal test cases.
Length11 min Posted Quest giverVGSources Team

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MySQL Error 1064 means the server’s SQL parser could not interpret your statement. Start at the text after near and inspect the token immediately before it, because the visible failure point is often just after the missing comma, quote, operator, or closing parenthesis that caused the problem. Then reduce the statement to the smallest failing example, check the server version and active sql_mode, and correct any reserved-word or quoting mismatch.

What MySQL Error 1064 actually means

Error 1064 is a syntax, or parser, error. MySQL received the statement but could not match its tokens to the grammar enabled by that server. The statement therefore fails before MySQL can perform the requested query operation.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A typical message looks like this:

ERROR 1064 (42000): 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 'FROM users' at line 1

The wording about checking the manual is generic diagnostic text, not proof that the manual is missing or that your account lacks permission. The useful part is the near fragment and its line number. MySQL reports where parsing stopped; the actual mistake may be the token immediately before that fragment.

For example, in this statement:

SELECT id name FROM users;

the parser may complain near name FROM, even though the missing comma is between id and name. Read one or two tokens backward, not just the displayed word.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

A practical first-response sequence

Use this order whenever a statement fails with 1064. It prevents you from changing server settings before you understand the statement.

  1. Save the complete evidence. Copy the entire SQL statement exactly as executed, the complete error message, the near text, and the reported line number. If an application generated the SQL, capture the final SQL sent to MySQL rather than only the source-code template.
  2. Inspect the reported area and the preceding token. Look for a misspelled keyword, a missing comma, an extra comma, unmatched parentheses, a missing operator, or a string that was never closed.
  3. Run the smallest statement that still fails. Remove selected columns, joins, filters, ordering, and other clauses until the error disappears. Add the removed pieces back one at a time; the first addition that reintroduces 1064 identifies the faulty fragment.
  4. Check the actual server version. Run SELECT VERSION();. Compare the syntax with the MySQL Reference Manual for that version. Features, grammar details, and reserved-word lists change between releases.
  5. Check the active SQL mode. Run SELECT @@sql_mode;. Modes can change how quotes, functions, and other syntax are interpreted.
  6. Review every identifier. Table, column, alias, role, and database names that are reserved words or contain special characters must be quoted or, preferably for a new schema, renamed.
  7. Normalize the text. Replace smart quotes with ordinary ASCII quotes, remove non-breaking spaces and zero-width characters, and retype suspicious punctuation. These characters are commonly introduced by web pages, PDFs, chat applications, and generated SQL.

How to read the “near … at line …” fragment

Use the line number as a location, not a diagnosis

The line number identifies where the parser stopped counting lines in the submitted statement. In a multi-line query, go directly to that line, then examine the previous line for an unclosed quote, parenthesis, or comma. A failure reported on line 8 can be caused by a missing delimiter on line 7.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Look backward from the displayed token

Suppose MySQL reports:

... near 'WHERE status = 1' at line 1

Possible causes include a missing comma before WHERE, a misspelled FROM clause, or an extra comma at the end of the selected column list. The word shown after near is not necessarily the bad word.

Check statement boundaries

When testing in a client, make sure the statement terminates with the client’s expected delimiter. A stored program, trigger, or procedure may require a temporary delimiter such as DELIMITER // in the MySQL command-line client; otherwise the client can send only part of the definition. If the server receives an incomplete definition, the resulting parser error can appear unrelated to the procedure body.

Common syntax causes and precise corrections

Misspelled or misplaced keywords

SQL keywords must match the grammar for the installed MySQL release. A typo such as SELEC, placing WHERE before FROM, or using a clause supported by another database engine produces 1064. Compare the clause order with the version-specific manual instead of relying on a query written for PostgreSQL, SQL Server, SQLite, or a different MySQL release.

-- Incorrect clause order
SELECT id WHERE active = 1 FROM users;

-- Correct order
SELECT id FROM users WHERE active = 1;

Missing, extra, or misplaced commas

Check column lists, function arguments, SET assignments, and value lists character by character. A trailing comma before a closing parenthesis is a frequent failure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
-- Missing comma
INSERT INTO users (name email) VALUES ('Ada', '[email protected]');

-- Correct
INSERT INTO users (name, email) VALUES ('Ada', '[email protected]');

-- Extra comma
SELECT id, name, FROM users;

-- Correct
SELECT id, name FROM users;

Unmatched parentheses

Count opening and closing parentheses around function calls, subqueries, and grouped conditions. Format nested expressions on separate lines so each closing parenthesis is visible.

-- Missing closing parenthesis
SELECT * FROM users WHERE (status = 'active' AND role = 'admin';

-- Correct
SELECT * FROM users WHERE (status = 'active' AND role = 'admin');

Missing operators

Adjacent expressions need an operator such as =, AND, OR, or a comma, depending on context. Concatenating two conditions without an operator causes the parser to stop at the second expression.

-- Missing AND
SELECT * FROM users WHERE active = 1 role = 'admin';

-- Correct
SELECT * FROM users WHERE active = 1 AND role = 'admin';

Unclosed or incorrectly quoted strings

String literals use single quotation marks. A missing closing quote can make the rest of the statement appear to be part of the string, so the reported location may be far from the actual omission.

-- Incorrect
SELECT * FROM users WHERE name = 'Ada;

-- Correct
SELECT * FROM users WHERE name = 'Ada';

Escape an apostrophe according to the string rules in use, or pass the value as a parameter through your database API. Do not solve a quoting problem by concatenating untrusted input into SQL.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Malformed clauses or function calls

Each clause has a defined shape. Check that aggregate functions have parentheses, aliases appear in valid positions, and operators are supported by the selected data type and server version. If a complex expression fails, test the function or clause by itself, then add surrounding expressions back gradually.

Reserved words and identifier quoting

MySQL reserves certain words for its grammar. The MySQL 8.4 Reference Manual states that reserved words can be used as identifiers when quoted, and its schema-object documentation says identifiers containing special characters or reserved words must be quoted whenever you refer to them.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Quote an existing object with backticks

Use the backtick character for MySQL identifiers:

SELECT `order` FROM orders;

Here, order is treated as a column name rather than as the keyword that introduces an ordering clause. Apply the same rule to table, database, alias, role, and column names.

Rename new objects when possible

Quoting is useful when you must preserve an existing schema, but a clearer name is usually better for a new design. Names such as order, select, or names containing punctuation force every future query to use delimiters and make migrations harder to read. Choose descriptive, non-reserved names before creating the table.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Account for function names and IGNORE_SPACE

With the IGNORE_SPACE SQL mode enabled, built-in function names are treated as reserved words in additional contexts. The historical MySQL documentation shows that a table named count can produce 1064 unless it is quoted. If a name that resembles a built-in function fails unexpectedly, inspect @@sql_mode and quote the identifier or rename it.

Quotes, ANSI_QUOTES, and sql_mode

Use the correct delimiter for each job

  • Single quotes: string literals such as 'Ada'.
  • Backticks: MySQL identifiers such as `order`.
  • Double quotes: normally usable for strings in some configurations, but not when ANSI_QUOTES is enabled.

When ANSI_QUOTES is enabled, double quotation marks delimit identifiers instead of strings. A statement written as WHERE name = "Ada" can therefore fail or behave differently because "Ada" is interpreted as an object name. Write string values with single quotes so the statement remains unambiguous.

-- Portable string literal
SELECT * FROM users WHERE name = 'Ada';

-- Identifier with a reserved name
SELECT `order` FROM orders;

Inspect the session, not just the server configuration

SELECT @@sql_mode; reports the mode for your current session. A connection pool, command-line client, migration tool, or application can set a session value that differs from the global setting. Capture the mode using the same connection that produced the error before changing anything.

Prefer statement fixes over global mode changes

Changing SQL mode globally can make one legacy statement work while changing the behavior of other applications. First correct the statement, quote or rename the identifier, and make the session’s assumptions explicit. Change a mode only when you understand its effect on every client and have a tested compatibility plan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Version and SQL-dialect mismatches

The phrase “check the manual that corresponds to your MySQL server version” matters because the server, not the editor or ORM, decides which grammar is valid. Confirm the version with:

SELECT VERSION();

Then verify that the syntax, keywords, functions, and reserved-word list belong to that version. SQL copied from another database engine can fail even when it looks familiar: quoting characters, pagination syntax, date functions, procedural statements, and conflict-handling clauses differ across engines.

Imported dumps and ORM-generated SQL deserve the same check. A migration created against one MySQL release may contain a keyword that became reserved in a later release, while an older server may not recognize a feature introduced later. Test migrations against the oldest server version you support and the exact mode used in production.

Reduce a complex query to a minimal failing example

Large statements hide the first syntax mistake. Use a controlled reduction:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Copy the statement into a scratch session so you do not edit the production command.
  2. Remove the final clause, then retry. Continue removing joins, expressions, and selected columns until the statement parses.
  3. Add the removed pieces back one at a time, executing after each addition.
  4. When one addition fails, reduce that fragment further: test its function call, subquery, or predicate independently.
  5. Once corrected, run the complete statement with the original values and mode.

For a query assembled by code, log the final SQL and bind values separately. A template can look correct while the generated text contains a doubled comma, an empty IN () list, an unescaped quote, or an identifier that came from user configuration.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Worked diagnosis examples

A reserved column name

-- Fails when order is parsed as a keyword
SELECT order FROM orders;

-- Immediate compatibility fix
SELECT `order` FROM orders;

If you control the schema, rename the column to a descriptive alternative and update dependent queries. If you do not, keep the backticks in every statement, view, trigger, and migration that references it.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

A quote-mode mismatch

-- Risky when ANSI_QUOTES is enabled
SELECT * FROM users WHERE name = "Ada";

-- Correct string delimiter
SELECT * FROM users WHERE name = 'Ada';

Check @@sql_mode on the failing connection. Do not assume the mode shown in a server configuration file is the mode inherited by an existing connection.

A comma before a clause

-- Parser stops near FROM
SELECT id, name, FROM users;

-- Remove the trailing comma
SELECT id, name FROM users;

The reported near 'FROM users' fragment points to where MySQL can no longer continue, while the extra comma is the preceding token that made the grammar invalid.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Invisible characters copied from formatted text

A query copied from a web page can contain a non-breaking space, smart quote, or zero-width character that looks ordinary in an editor. Paste into a plain-text editor, retype the punctuation around the failure, and compare the byte sequence if the visible text appears correct. Generated SQL should be emitted as plain ASCII punctuation unless the server grammar explicitly requires another character.

Choosing among possible fixes

Fix When it fits Trade-off
Correct the statement A typo, delimiter, clause order, quote, or operator is wrong Usually the most portable and maintainable approach
Quote the identifier with backticks An existing table or column is a reserved word or contains special characters Preserves the schema but requires consistent quoting
Rename the identifier You control a new or changeable schema Cleaner long-term SQL, but dependent code and migrations must be updated
Change session or server SQL mode Compatibility with a known legacy workload requires a mode difference Can alter parsing for unrelated statements; validate all clients first
Rewrite for the installed version The statement came from another MySQL release or another SQL engine Restores version correctness, but may reduce cross-engine similarity

Evaluate each option against five questions: Is it valid for the installed MySQL version? Will it remain portable to other engines you support? Is the result readable and maintainable? Can the schema be renamed safely? Is a session or server mode change acceptable for every application using the database?

Preventing recurring 1064 failures

  • Run migrations and queries in the same MySQL major and minor version family used in production.
  • Record the connection’s @@sql_mode in diagnostic logs when syntax behavior is surprising.
  • Keep identifiers descriptive and avoid reserved words and built-in function names.
  • Use parameterized statements for values; do not construct string literals by concatenating input.
  • Format generated SQL so commas, parentheses, and clause boundaries are visible in logs.
  • Validate empty collections before generating IN lists and optional clauses.
  • Keep copied SQL in plain text and watch for smart punctuation or invisible Unicode characters.
  • Test stored programs with the client’s delimiter rules and execute the complete definition, not a truncated selection.
  • When upgrading MySQL, review the new reserved-word list and run representative migrations before changing production.

When the error persists after an apparent correction

Recheck that the corrected text is the text actually sent to the server. Application logs may show a template while the driver adds clauses, substitutes an empty value, or uses a different connection mode. Confirm the active database, server version, and session sql_mode on that connection.

If a minimal statement still fails, compare every character around the reported location, including quotation marks and whitespace. Retype the fragment manually, then add the original clauses back incrementally. This isolates whether the remaining problem is grammar, an identifier rule, a mode difference, or a transformation performed by the client before MySQL receives the SQL.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Key points to retain

  • 1064 is a parser failure, not a data or permission error.
  • The near text marks where parsing stopped; inspect the token immediately before it.
  • Commas, parentheses, operators, keywords, and string quotes account for many failures.
  • Use single quotes for strings and backticks for identifiers; ANSI_QUOTES changes double-quote behavior.
  • Reserved words and function names may require quoting or a schema rename.
  • Match the statement to the actual MySQL version and session SQL mode, especially for imported or ORM-generated SQL.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.