View previous topic :: View next topic |
Author |
Message |
Dr_Stein Guru
Joined: 21 Mar 2003 Posts: 303 Location: Mountain View, CA
|
Posted: Fri Nov 04, 2005 12:26 am Post subject: [solved] importing a mysql db |
|
|
I am trying to move a mysql db from one machine to another.
both boxes have 4.0.25-r2 on them.
It's an old pMachine db, and it's working fine on the old host.
On the new host, when I run mysql, I get this:
jnichols@box ~/blah $ mysql -uroot -p(password) tktblog < tktblog.sql
ERROR 1064 at line 195: 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 'default char(3) NOT NULL default 'yes',
PRIMARY KEY (id)
) T
jnichols@box ~/blah $
Line 195 is pretty boring..
191 --
192 -- Table structure for table `pm_mailinglist`
193 --
194
195 CREATE TABLE pm_mailinglist (
196 id int(10) unsigned NOT NULL auto_increment,
197 email varchar(100) NOT NULL default '',
198 weblog char(3) NOT NULL default 'no',
199 default char(3) NOT NULL default 'yes',
200 PRIMARY KEY (id) 201 ) TYPE=MyISAM;
--
I have no idea why this isn't working. My mysql foo is weak. I asked on IRC (not in #gentoo) and turkeys just tell me to Google for it. Problem with Google these days is that there is so much irrelevant information about other versions of mysql that it'll take me ages to find the answer. My Googling & reading mysql docs have brought me no results.
Both versions of mysqldump are:
"mysqldump Ver 9.11 Distrib 4.0.25, for pc-linux-gnu (i686)"
If I can just take the stuff from /var/lib/mysql, I am willing to do that. There are just 2 small databases that I need to extract off of this old machine.
Otherwise.. anyone know a solution to this?
Last edited by Dr_Stein on Fri Nov 04, 2005 8:40 pm; edited 1 time in total |
|
Back to top |
|
|
heartburn n00b
Joined: 18 Oct 2002 Posts: 40
|
Posted: Fri Nov 04, 2005 1:07 am Post subject: |
|
|
I think "DEFAULT" is a sql keyword, as in:
Code: | set column_name = DEFAULT |
- or - (see line 199)
Code: | field_name char(3) not null DEFAULT 'yes' |
I don't have much experience with MySQL, but I'm pretty good with SQL. I would have picked a better field name.
First I'd try quoting the field name:
Code: | 'default' char(3) NOT NULL default 'yes' |
then I'd try bracing it:
Code: | [default] char(3) NOT NULL default 'yes' |
That, or something similar should work.
It's kinda' strange that mysqldump would produce syntax that MySQL can't read. I would say that's a bug. You may want to tell the authors of the script that created your database to avoid using sql keywords as object names. And the authors of mysqldump should probably quote MySQL keywords used as object names. Better yet, maybe they should quote EVERY user defined name.
You should also be aware that, further down in your script, you may see lines like:
Code: |
insert into pm_mailinglist(id, email, weblog, default)
values (1, 'whoever@whatever.org', 'somepath', 'yes')
|
These may fail too, even if you've fixed the ddl above. And there could be MANY of them. You'd have to do a global search & replace to make DEFAULT into 'DEFAULT' (or whatever the quoted value is for MySQL). But you have to avoid replacing any legitimate occurances of the word "DEFAULT".
Here's what I'd do:
1) TEMPORARILY change the name of the "default" field using whatever client you're accustomed to (phpMySQL, mysql client). Change it to a name that's not a keyword, and is extremely unlikely to appear anywhere in your database. Something like "OIKJFOIGHRPOIUGHPIDUFHIUDGHP" might be good.
2) Generate your SQL file with mysqldump.
3) Change the name back to "default" in the original database so it continues to work.
4) Replace all occurences of "OIKJFOIGHRPOIUGHPIDUFHIUDGHP" in your mysqldump file with the legally quoted value of 'default'
5) Cross your fingers.
6) Run your script.
Hope that helps.
Last edited by heartburn on Fri Nov 04, 2005 2:19 am; edited 1 time in total |
|
Back to top |
|
|
Mad Merlin Veteran
Joined: 09 May 2005 Posts: 1155
|
Posted: Fri Nov 04, 2005 2:19 am Post subject: |
|
|
Indeed, the previous poster got the idea. You need `default` (note those are backticks, not regular single quotes) rather than just default, as it is a keyword. You can have mysqldump generate quoted fields rather than unquoted ones, I believe it's the default, but I could be wrong. It might depend on what compatibility mode it's used in, as I know other databases use different quotes, I don't know if ANSI SQL specifies any particular quoting style. |
|
Back to top |
|
|
heartburn n00b
Joined: 18 Oct 2002 Posts: 40
|
Posted: Fri Nov 04, 2005 2:58 am Post subject: |
|
|
Thanks Mad Merlin!
So, given Mad Merlin's insight, I'd do this:
1) Check the mysqldump man pages to see if there's an option to quote identifiers
If so, use it. If Not:
1) TEMPORARILY change the name of the "default" field in the pm_mailinglist table to something like "OIKJFOIGHRPOIUGHPIDUFHIUDGHP".
2) Generate your SQL file with mysqldump.
3) Change the name of the field back to "default" in the original database so it continues to work.
4) Replace all occurences of "OIKJFOIGHRPOIUGHPIDUFHIUDGHP" in your mysqldump file to `default` (backticks)
5) Cross your fingers.
6) Run your script. |
|
Back to top |
|
|
heartburn n00b
Joined: 18 Oct 2002 Posts: 40
|
Posted: Fri Nov 04, 2005 3:08 am Post subject: |
|
|
I just checked the mysqldump docs. You want to use the "-Q" (--quote-names) option to quote identifiers. That's all you should need to do. I wonder why that's not the default. |
|
Back to top |
|
|
Dr_Stein Guru
Joined: 21 Mar 2003 Posts: 303 Location: Mountain View, CA
|
Posted: Fri Nov 04, 2005 8:39 pm Post subject: |
|
|
Wow. I never in a million years would have thought of that.
I re-did the mysqldump with the -Q flag, and was able to import the database successfully.
Thanks! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|