- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How do I insert a special character such as ' (single quote) into MySQL?
To insert a special character such as “ ‘ “ (single quote) into MySQL, you need to use \’ escape character. The syntax is as follows −
insert into yourTableName(yourColumnName) values(' yourValue\’s ');
To understand the above syntax, let us create two tables. The query to create first table is as follows −
mysql> create table AvoidInsertErrorDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Sentence text -> ); Query OK, 0 rows affected (0.53 sec)
Now you can insert special character such as ‘ in the table using insert command. The query is as follows −
mysql> insert into AvoidInsertErrorDemo(Sentence) values('a woman\'s hat'); Query OK, 1 row affected (0.16 sec) mysql> insert into AvoidInsertErrorDemo(Sentence) values('Mrs. Chang\'s house'); Query OK, 1 row affected (0.31 sec)
Display all records from the table using select statement:
mysql> select *from AvoidInsertErrorDemo;
The following is the output −
+----+--------------------+ | Id | Sentence | +----+--------------------+ | 1 | a woman's hat | | 2 | Mrs. Chang's house | +----+--------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to display a single quote text as a column value in MySQL?
- How do I insert multiple values in a column with a single MySQL query?
- How to insert into two tables using a single MySQL query?
- How do I get the id after INSERT into MySQL database in Python?
- How do I insert a NULL value in MySQL?
- How to insert only a single column into a MySQL table with Java?
- How can I update MySQL table after quoting the values of a column with a single quote?
- How do I insert a JPEG image into a Python Tkinter window?
- MySQL: How can I find a value with special character and replace with NULL?
- How do I insert a record from one Mongo database into another?
- How do we insert/store a file into MySQL database using JDBC?
- How do I INSERT INTO from one MySQL table into another table and set the value of one column?
- Difference between single quote (‘) and double quote (“) in PowerShell?
- MySQL query to concatenate records with similar corresponding ids in a single row separated by a special character
- How do I insert all elements from one list into another in Java?