Converting Strings to Integers in MySQL
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Secondary keywords: mysql convert int to string Type: Blog Post
In MySQL, at some point you’ll probably need to convert string values to integers for one data operation or another. This post covers how to achieve this conversion using the CAST() and CONVERT() functions.
CAST() in MySQL?You can convert a string to an integer in MySQL using the CAST() function:
CAST(string_value AS SIGNED INTEGER)
Replace string_value with the column or string literal you intend to convert to an integer.
SELECT CAST('123' AS SIGNED INTEGER);
This query returns 123 as an integer.
CONVERT() in MySQL?Another method to perform this conversion in MySQL is by using the CONVERT() function. Here’s the syntax:
CONVERT(string_value, SIGNED INTEGER)
Replace string_value with the value you want to convert.
SELECT CONVERT('456', SIGNED INTEGER);
This query also returns 456 as an integer.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.