Enjoy an ad free experience by logging in. Not a member yet?
Register .
07-23-2012, 04:09 PM
PM User |
#1
Senior Coder
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
moving column with invalid character
hello, I made a typo while I was added a column to a table in mysql.
the column name is like "MyField\"
because of this typo I can no longer review the table in my editor. and I'm unable to remove the column using my client software or a linux console.
any ideas?
07-23-2012, 06:15 PM
PM User |
#2
Senior Coder
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
is there data in it? can you do something like Script-table and then drop table, then create (via the script)?
07-23-2012, 06:19 PM
PM User |
#3
Senior Coder
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
there is no data in the column, any every attempt I've made to remove the column fails. is there maybe someway to escape the bad character? I can't really remove the table as it's the transactions table for a very busy web store.
07-23-2012, 06:34 PM
PM User |
#4
New Coder
Join Date: Mar 2009
Posts: 89
Thanks: 5
Thanked 14 Times in 14 Posts
Hi, you can get the exact column name via console and show create table query. Than run alter table in console using backticks around column name and escaping backslashes:
Quote:
mysql> create table testtable(id int,`MyField\\` varchar(255));
Query OK, 0 rows affected (0.07 sec)
mysql> show create table testtable;
+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| testtable | CREATE TABLE `testtable` (
`id` int(11) DEFAULT NULL,
`MyField\\` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> alter table testtable change `MyField\\` MyField varchar(255);
Query OK, 0 rows affected (0.19 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table testtable;
+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| testtable | CREATE TABLE `testtable` (
`id` int(11) DEFAULT NULL,
`MyField` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
__________________
URL2SEO URL shortener and redirection services
07-23-2012, 06:52 PM
PM User |
#5
Senior Coder
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
I would do that if my column name has two slashes in it, but it only has one, which is what is causing the issue.
PHP Code:
mysql > ALTER TABLE ` Transactions ` DROP COLUMN ` IDEBIT_VERSION\`;
07-23-2012, 07:00 PM
PM User |
#6
Senior Coder
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
I don't know about MySQL syntax, but in a lot of languages \\ is the escape sequence for a single \
07-23-2012, 07:04 PM
PM User |
#7
Senior Coder
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
Yes, I've tried that as well.
still no luck, and now I also can't do a backup of the table or the database. it's causing the program to hang.
07-23-2012, 07:25 PM
PM User |
#8
Senior Coder
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
Ok, i've finally got it sorted, from the command line I was able to make a backup of the table, I changed the table name in the sql file and uploaded it back into the database, I dropped the original table and changed the name of the new table to that of the old one and I'm back in business!
thanks for all your help!
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 06:12 AM .
Advertisement
Log in to turn off these ads.