Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-23-2012, 04:09 PM   PM User | #1
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
Question 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?
angst is offline   Reply With Quote
Old 07-23-2012, 06:15 PM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
is there data in it? can you do something like Script-table and then drop table, then create (via the script)?
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 07-23-2012, 06:19 PM   PM User | #3
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
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.
angst is offline   Reply With Quote
Old 07-23-2012, 06:34 PM   PM User | #4
koko5
New Coder

 
Join Date: Mar 2009
Posts: 89
Thanks: 5
Thanked 14 Times in 14 Posts
koko5 is an unknown quantity at this point
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
koko5 is offline   Reply With Quote
Old 07-23-2012, 06:52 PM   PM User | #5
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
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 `TransactionsDROP COLUMN `IDEBIT_VERSION\`; 
angst is offline   Reply With Quote
Old 07-23-2012, 07:00 PM   PM User | #6
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
I don't know about MySQL syntax, but in a lot of languages \\ is the escape sequence for a single \
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 07-23-2012, 07:04 PM   PM User | #7
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
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.
angst is offline   Reply With Quote
Old 07-23-2012, 07:25 PM   PM User | #8
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
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!
angst is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:12 AM.


Advertisement
Log in to turn off these ads.