Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a column for UTF-8 content in MySQL

Tags:

sql

mysql

ddl

Anybody has ideas, how to add a column meant for storing UTF-8 content in MySQL?

I tried the following:

ALTER TABLE tname ADD COLUMN cname TEXT CHARACTER SET utf8 COLLATE utf8_general_ci IF NOT EXISTS;

That gives an error:

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 'if not exists' at line 1


I want to add a new column with UTF-8 encoding.

Thanks.

like image 790
user2301515 Avatar asked Apr 25 '13 13:04

user2301515


People also ask

How do I set MySQL database to UTF-8?

To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace dbname with the database name: Copy ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci; To exit the mysql program, type \q at the mysql> prompt.

How do I add a column to a MySQL database?

Use ADD to add new columns to a table, and DROP to remove existing columns. DROP col_name is a MySQL extension to standard SQL. To add a column at a specific position within a table row, use FIRST or AFTER col_name . The default is to add the column last.

How do I add a column in Tableplus?

Insert columnOpen the table structure view ( ⌘ + ^ + ] ) Click on the + Column button at the bottom, or double click on the blank row under column section, or use shortcut key ⌘ + I when selecting a column.


1 Answers

This is not a valid syntax for ALTER TABLE.

Here is the correct way:

ALTER TABLE tname ADD COLUMN cname TEXT CHARACTER SET utf8 COLLATE utf8_general_ci;
like image 53
Omesh Avatar answered Sep 27 '22 17:09

Omesh