How to get a table creation script in MySQL Workbench? - mysql

I am rolling back to MySQL GUI Tools' MySQL Query Browser since I can't find the shortcut to get a table's creation script in MySQL Workbench.

I cannot find such an option either, at least in the Community edition.
I suppose this corresponds to the Reverse Engineering feature, which, unfortunately, is only available in the commercial edition (quoting) :
reverse engineering a database
directly from a MySQL server applies
to commercial versions of MySQL
Workbench only.
Still, you can use plain-SQL to get the create table instruction that will allow you to create a table.
For instance, the following query :
show create table url_alias;
when executed on a drupal database, would give, when using right click > copy field content on the result :
'CREATE TABLE `url_alias` (
`pid` int(10) unsigned NOT NULL auto_increment,
`src` varchar(128) NOT NULL default '''',
`dst` varchar(128) NOT NULL default '''',
`language` varchar(12) NOT NULL default '''',
PRIMARY KEY (`pid`),
UNIQUE KEY `dst_language` (`dst`,`language`),
KEY `src_language` (`src`,`language`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8'
Unfortunately (again), MySQL Workbench adds some quotes everywhere when copying this way :-(
EDIT: Using MySQL 8.0, there is an option to right click > copy field (unquoted) on the result to get the desired result without quotes.
In the end, the simplest solution, except from staying with MySQL Query Browser, will most likely be to connect to the database, using the command-line client, and execute the show create table query from there :
mysql> show create table url_alias\G
*************************** 1. row ***************************
Table: url_alias
Create Table: CREATE TABLE `url_alias` (
`pid` int(10) unsigned NOT NULL auto_increment,
`src` varchar(128) NOT NULL default '',
`dst` varchar(128) NOT NULL default '',
`language` varchar(12) NOT NULL default '',
PRIMARY KEY (`pid`),
UNIQUE KEY `dst_language` (`dst`,`language`),
KEY `src_language` (`src`,`language`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
Getting "the right portion" of the output is easier, there : no quote to remove.
And, just for the sake of completness, you could also use mysqldump to get your table's structure :
mysqldump --no-data --user=USERNAME --password=PASSWORD --host=HOST DATABASE_NAME TABLE_NAME
Using the --no-data switch, you'll only get the structure -- in the middle of some mode settings and all that.

To get an individual table's creation script just right click on the table name and click Copy to Clipboard > Create Statement.
To enable the File > Forward Engineering SQL_CREATE Script.. option and to get the creation script for your entire database :
Database > Reverse Engineer (Ctrl+R)
Go through the steps to create the EER Diagram
When viewing the EER Diagram click File > Forward Engineering SQL_CREATE Script... (Ctrl+Shift+G)

Right-click on the relevant table and choose either of:
Copy to Clipboard > Create Statement
Send to SQL Editor > Create Statement
That seems to work for me.

It is located in server administration rather than in SQL development.
From the home screen select the database server instance your database is located on from the server administration section on the far right.
From the menu on the right select Data Export.
Select the database you want to export and choose a location.
Click start export.

Simply use:
show create table <table_name>

I came here looking for the answer to the same question. But I found a much better answer myself.
In the tables list, if you right-click on the table name there is a suite of CRUD script generation options in "Send to SQL Editor". You can select multiple tables and take the same approach too.
My version of MySQL Workbench: 5.2.37

Not sure if I fully understood your problem, but if it's just about creating export scripts, you should forward engineer to SQL script - Ctrl + Shift + G or File -> Export -> first option.

1 use command
show create table test.location
right click on selected row and choose Open Value In Viewer
select tab Text

Solution for MySQL Workbench 6.3E
On left panel, right click your table and selecct "Table Inspector"
On center panel, click DDL label

In "model overview" or "diagram" just right-click on the table and you have the folowing options: "Copy Insert to clipboard" OR "Copy SQL to clipboard"

Not sure if this is still an issue, but for me in 5.2.35CE it's possible to get the create scripts by:
Database --> Reverse Engineer
Under stored connection, choose your database
Hit "Next" a few times, choose which schema you want to reverse engineer, and let the tool work
You'll get an "EER Diagram" view with all the DB's schema. If you right click on the table you care about and choose "Copy SQL to Clipboard" I think you'll have what you need.
Hopefully this helps someone else that needs it.

Open MySQL Workbench (6.3 CE)
In "Navigator" select "Management"
Then select "Data Export" (Here select the table whose create script you wish to export)
In Drop down select "Dump Structure and Data"
Select checkbox "Include Create Schema"
Click the button "Start Export"
Once export is complete it will display the location in which exported file is dumped in your system. Go to the location and open the exported file to find table creation script.
Or Check https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-management.html

U can use MySQL Proxy and its scripting system to view SQL queries in realtime in the terminal.

Related

Importing database from mysql dump file [duplicate]

Error
SQL query:
--
-- Database: `work`
--
-- --------------------------------------------------------
--
-- Table structure for table `administrators`
--
CREATE TABLE IF NOT EXISTS `administrators` (
`user_id` varchar( 30 ) NOT NULL ,
`password` varchar( 30 ) NOT NULL ) ENGINE = InnoDB DEFAULT CHARSET = latin1;
MySQL said:
#1046 - No database selected
need some help here.
You need to tell MySQL which database to use:
USE database_name;
before you create a table.
In case the database does not exist, you need to create it as:
CREATE DATABASE database_name;
followed by:
USE database_name;
You can also tell MySQL what database to use (if you have it created already):
mysql -u example_user -p --database=example < ./example.sql
I faced the same error when I tried to import a database created from before. Here is what I did to fix this issue:
1- Create new database
2- Use it by use command
3- Try again
This works for me.
If you're trying to do this via the command line...
If you're trying to run the CREATE TABLE statement from the command line interface, you need to specify the database you're working in before executing the query:
USE your_database;
Here's the documentation.
If you're trying to do this via MySQL Workbench...
...you need to select the appropriate database/catalog in the drop down menu found above the :Object Browser: tab. You can specify the default schema/database/catalog for the connection - click the "Manage Connections" options under the SQL Development heading of the Workbench splash screen.
Addendum
This all assumes there's a database you want to create the table inside of - if not, you need to create the database before anything else:
CREATE DATABASE your_database;
If you are doing this through phpMyAdmin:
I'm assuming you already Created a new MySQL Database on Live Site (by live site I mean the company your hosting with (in my case Bluehost)).
Go to phpMyAdmin on live site - log in to the database you just created.
Now IMPORTANT! Before clicking the "import" option on the top bar, select your database on the left side of the page (grey bar, on the top has PHP Myadmin written, below it two options:information_schema and name of database you just logged into.
once you click the database you just created/logged into it will show you that database and then click the import option.
That did the trick for me. Really hope that helps
For MySQL Workbench
Select database from Schemas tab by right mouse clicking.
Set database as Default Schema
Edit your SQL file using Notepad or Notepad++
add the following 2 line:
CREATE DATABASE NAME;
USE NAME;
Assuming you are using the command line:
1. Find Database
show databases;
2. Select a database from the list
e.g. USE classicmodels; and you should be off to the races! (Obviously, you'll have to use the correctly named database in your list.
Why is this error occurring?
Mysql requires you to select the particular database you are working on. I presume it is a design decision they made: it avoids a lot of potential problems: e.g. it is entirely possible, for you to use the same table names across multiple databases e.g. a users table. In order to avoid these types of issues, they probably thought: "let's make users select the database they want".
If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!
be careful about blank passwords
mysqldump [options] -p '' --databases database_name
will ask for a password and complain with mysqldump: Got error: 1046: "No database selected" when selecting the database
the problem is that the -p option requires that there be no space between -p and the password.
mysqldump [options] -p'' --databases database_name
solved the problem (quotes are not needed anymore).
Check you have created the database first which you want.
If you have not created the dataBase you have to fire this query:
CREATE DATABASE data_base_name
If you have already created the database then you can simply fire this query and you will be able to create table on your database:
CREATE TABLE `data_base_name`.`table_name` (
_id int not null,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (_id)
);
Solution with an Example
Error 1046 occurs when we miss to connect our table with a database. In this case, we don't have any database and that’s why at first we will create a new database and then will instruct to use that database for the created table.
# At first you have to create Database
CREATE DATABASE student_sql;
# Next, specify the database to use
USE student_sql;
# Demo: create a table
CREATE TABLE student_table(
student_id INT PRIMARY KEY,
name VARCHAR(20),
major VARCHAR(20)
);
# Describe the table
describe student_table;
quoting ivan n :
"If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!"
These are the steps:
Create a Database, for instance my_db1, utf8_general_ci.
Then click to go inside this database.
Then click "import", and select the database: my_db1.sql
That should be all.
first select database : USE db_name
then creat table:CREATE TABLE tb_name
(
id int,
name varchar(255),
salary int,
city varchar(255)
);
this for mysql 5.5 version syntax
I'm late i think :] soory,
If you are here like me searching for the solution when this error occurs with mysqldump instead of mysql, try this solution that i found on a german website out there by chance, so i wanted to share with homeless people who got headaches like me.
So the problem occurs because the lack -databases parameter before the database name
So your command must look like this:
mysqldump -pdbpass -udbuser --databases dbname
Another cause of the problem in my case was that i'm developping on local and the root user doesn't have a password, so in this case you must use --password= instead of -pdbpass, so my final command was:
mysqldump -udbuser --password= --databases dbname
Link to the complete thread (in German) : https://marius.bloggt-in-braunschweig.de/2016/04/29/solution-mysqldump-no-database-selected-when-selecting-the-database/
In Amazon RDS, merely writing use my-favorite-database does not work if that database's name includes dashes. Furthermore, none of the following work, either:
use "my-favorite-database"
use `my-favorite-database`
use 'my-favorite-database'
Just click the "Change Database" button, select the desired database, and voilà.
Although this is a pretty old thread, I just found something out. I created a new database, then added a user, and finally went to use phpMyAdmin to upload the .sql file. total failure. The system doesn't recognize which DB I'm aiming at...
When I start fresh WITHOUT first attaching a new user, and then perform the same phpMyAdmin import, it works fine.
Just wanted to add: If you create a database in mySQL on a live site, then go into PHPMyAdmin and the database isn't showing up - logout of cPanel then log back in, open PHPMyAdmin, and it should be there now.
For an added element of safety, when working with multiple DBs in the same script you can specify the DB in the query, e.g. "create table my_awesome_db.really_cool_table...".
jst create a new DB in mysql.Select that new DB.(if you r using mysql phpmyadmin now on the top it'l be like 'Server:...* >> Database ).Now go to import tab select file.Import!

I have an older .sql file (exported from 5.0.45) I am trying to import into a newer version of MySQL via phpMyAdmin. Receiving errors

Receiving the following error message:
Error
Static analysis:
1 errors were found during analysis.
This option conflicts with "AUTO_INCREMENT". (near "AUTO_INCREMENT" at position 692)
SQL query:
-- phpMyAdmin SQL Dump -- version 2.8.2.4 -- http://www.phpmyadmin.net -- -- Host: localhost:3306 -- Generation Time: Mar 23, 2020 at 03:58 PM -- Server version: 5.0.45 -- PHP Version: 5.2.3 -- -- Database: weir-jones -- -- -------------------------------------------------------- -- -- Table structure for table categories -- CREATE TABLE categories ( number int(11) NOT NULL auto_increment, section varchar(255) NOT NULL, parent_id varchar(10) NOT NULL, title varchar(200) NOT NULL, type varchar(255) NOT NULL, content text NOT NULL, display_order int(11) NOT NULL, PRIMARY KEY (number) ) ENGINE=MyISAM AUTO_INCREMENT=126 DEFAULT CHARSET=utf8 AUTO_INCREMENT=126
MySQL said: Documentation
1046 - No database selected
============================================
I have tried importing with all compatibility modes. No luck.
old database is gone, cannot export again.
Any help would be appreciated.
Brendan
If you ask for the 1046 No database selected then it is what it means. You exported a table from a database without the USE xxx.
So I would suggest try importing this within a database or add the USE clause on top on your SQL file.
Another thing:
If you ask a question on Stackoverflow make sure to read the "formatting rules". Wich means you can organzie your question.
It is actually quite hard to read what error you have. Use emphasis, code blocks and such things like:
CREATE table_blub
col1 CHAR(120) NOT NULL,
col2 INT(5)...
By this someone can better read what is code and what is the error and of course what is the actual question.
Eurobetics is correct, this is because the .sql file doesn't specify what database to work with. That's no problem, you can just create the database on your new server and import the file in to that. Since you're importing through phpMyAdmin, first use the "New" text in the left-hand navigation area to create a new database (you don't need to put any tables in it). Once the database is created, phpMyAdmin puts you in the database structure page. (If you happen to navigate away or are coming back after you've already created the database, just click the existing database in the navigation pane). Look at the tabs along the top row and use the "Import" tab there (or drag and drop your .sql file here).
Being inside that database page tells phpMyAdmin that you want to import to that database specifically, whereas if you're on the main home page, the Import button there isn't attached to any particular database, which leads to your error.
You could technically add the SQL commands to create the database and USE the database in to the .sql file, but in this case that doesn't seem like it's needed and would just be making more work for you.

Error while importing SQL database from local to server

I know this question has been asked before but I still couldn't get it fixed. I'm getting a #1046 error while importing my WP database from local to server. Here is what I get :
CREATE TABLE `wp_cntctfrm_field` (
`id` int(11) NOT NULL,
`name` char(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
MySQL a répondu (Translation: MYSQL responded) : Documentation
1046 - Aucune base n'a été sélectionnée(translation : no database was selected)
It's the first time I do it so I followed a tutorial but nothing seems to make it work.
You must select the target database you want to use to create/populate the database schema in.
You can select the target database at a global level for instance with Mysql Workbench in the left side, right hand click on the database you want to populate and select "Set as default schema".
You can also define the target database upon each SQL query.
For instance with your example, if the target database is named targetdb :
CREATE TABLE targetdb.wp_cntctfrm_field ( id int(11) NOT NULL, name char(100) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8
Please note that the target database must be created first with the appropriate CREATE DATABASE clause.
Hope this helps
You can use mysql -u <user> <DB_name> <<filename>
or add use <db_name>; at top of your dump file

Exporting/Importing all local MySQL databases - Error #1046 - No database selected - Multiple databases [duplicate]

Error
SQL query:
--
-- Database: `work`
--
-- --------------------------------------------------------
--
-- Table structure for table `administrators`
--
CREATE TABLE IF NOT EXISTS `administrators` (
`user_id` varchar( 30 ) NOT NULL ,
`password` varchar( 30 ) NOT NULL ) ENGINE = InnoDB DEFAULT CHARSET = latin1;
MySQL said:
#1046 - No database selected
need some help here.
You need to tell MySQL which database to use:
USE database_name;
before you create a table.
In case the database does not exist, you need to create it as:
CREATE DATABASE database_name;
followed by:
USE database_name;
You can also tell MySQL what database to use (if you have it created already):
mysql -u example_user -p --database=example < ./example.sql
I faced the same error when I tried to import a database created from before. Here is what I did to fix this issue:
1- Create new database
2- Use it by use command
3- Try again
This works for me.
If you're trying to do this via the command line...
If you're trying to run the CREATE TABLE statement from the command line interface, you need to specify the database you're working in before executing the query:
USE your_database;
Here's the documentation.
If you're trying to do this via MySQL Workbench...
...you need to select the appropriate database/catalog in the drop down menu found above the :Object Browser: tab. You can specify the default schema/database/catalog for the connection - click the "Manage Connections" options under the SQL Development heading of the Workbench splash screen.
Addendum
This all assumes there's a database you want to create the table inside of - if not, you need to create the database before anything else:
CREATE DATABASE your_database;
If you are doing this through phpMyAdmin:
I'm assuming you already Created a new MySQL Database on Live Site (by live site I mean the company your hosting with (in my case Bluehost)).
Go to phpMyAdmin on live site - log in to the database you just created.
Now IMPORTANT! Before clicking the "import" option on the top bar, select your database on the left side of the page (grey bar, on the top has PHP Myadmin written, below it two options:information_schema and name of database you just logged into.
once you click the database you just created/logged into it will show you that database and then click the import option.
That did the trick for me. Really hope that helps
For MySQL Workbench
Select database from Schemas tab by right mouse clicking.
Set database as Default Schema
Assuming you are using the command line:
1. Find Database
show databases;
2. Select a database from the list
e.g. USE classicmodels; and you should be off to the races! (Obviously, you'll have to use the correctly named database in your list.
Why is this error occurring?
Mysql requires you to select the particular database you are working on. I presume it is a design decision they made: it avoids a lot of potential problems: e.g. it is entirely possible, for you to use the same table names across multiple databases e.g. a users table. In order to avoid these types of issues, they probably thought: "let's make users select the database they want".
Edit your SQL file using Notepad or Notepad++
add the following 2 line:
CREATE DATABASE NAME;
USE NAME;
If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!
be careful about blank passwords
mysqldump [options] -p '' --databases database_name
will ask for a password and complain with mysqldump: Got error: 1046: "No database selected" when selecting the database
the problem is that the -p option requires that there be no space between -p and the password.
mysqldump [options] -p'' --databases database_name
solved the problem (quotes are not needed anymore).
Check you have created the database first which you want.
If you have not created the dataBase you have to fire this query:
CREATE DATABASE data_base_name
If you have already created the database then you can simply fire this query and you will be able to create table on your database:
CREATE TABLE `data_base_name`.`table_name` (
_id int not null,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (_id)
);
Solution with an Example
Error 1046 occurs when we miss to connect our table with a database. In this case, we don't have any database and that’s why at first we will create a new database and then will instruct to use that database for the created table.
# At first you have to create Database
CREATE DATABASE student_sql;
# Next, specify the database to use
USE student_sql;
# Demo: create a table
CREATE TABLE student_table(
student_id INT PRIMARY KEY,
name VARCHAR(20),
major VARCHAR(20)
);
# Describe the table
describe student_table;
quoting ivan n :
"If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!"
These are the steps:
Create a Database, for instance my_db1, utf8_general_ci.
Then click to go inside this database.
Then click "import", and select the database: my_db1.sql
That should be all.
first select database : USE db_name
then creat table:CREATE TABLE tb_name
(
id int,
name varchar(255),
salary int,
city varchar(255)
);
this for mysql 5.5 version syntax
I'm late i think :] soory,
If you are here like me searching for the solution when this error occurs with mysqldump instead of mysql, try this solution that i found on a german website out there by chance, so i wanted to share with homeless people who got headaches like me.
So the problem occurs because the lack -databases parameter before the database name
So your command must look like this:
mysqldump -pdbpass -udbuser --databases dbname
Another cause of the problem in my case was that i'm developping on local and the root user doesn't have a password, so in this case you must use --password= instead of -pdbpass, so my final command was:
mysqldump -udbuser --password= --databases dbname
Link to the complete thread (in German) : https://marius.bloggt-in-braunschweig.de/2016/04/29/solution-mysqldump-no-database-selected-when-selecting-the-database/
In Amazon RDS, merely writing use my-favorite-database does not work if that database's name includes dashes. Furthermore, none of the following work, either:
use "my-favorite-database"
use `my-favorite-database`
use 'my-favorite-database'
Just click the "Change Database" button, select the desired database, and voilà.
Although this is a pretty old thread, I just found something out. I created a new database, then added a user, and finally went to use phpMyAdmin to upload the .sql file. total failure. The system doesn't recognize which DB I'm aiming at...
When I start fresh WITHOUT first attaching a new user, and then perform the same phpMyAdmin import, it works fine.
Just wanted to add: If you create a database in mySQL on a live site, then go into PHPMyAdmin and the database isn't showing up - logout of cPanel then log back in, open PHPMyAdmin, and it should be there now.
For an added element of safety, when working with multiple DBs in the same script you can specify the DB in the query, e.g. "create table my_awesome_db.really_cool_table...".
jst create a new DB in mysql.Select that new DB.(if you r using mysql phpmyadmin now on the top it'l be like 'Server:...* >> Database ).Now go to import tab select file.Import!

phpMyAdmin export/import results in duplicate primary key error

I want to globally replace all instances of my site url in the Wordpress MySQL database with a new site url. To do that, I'm using phpMyAdmin to export the database to a .sql file, then doing a global replace in a text editor, then using phpMyAdmin to import the .sql file.
During the import, I'm encountering a duplicate entry for primary key error. Trying to debug this, I exported the file, then imported the identical file, making no changes and I still get the same error.
I appreciate any help solving this.
--
-- Dumping data for table `wp_comments`
--
INSERT INTO `wp_comments`
(`comment_ID`, `comment_post_ID`, `comment_author`, `comment_author_email`
,`comment_author_url`, `comment_author_IP`, `comment_date`, `comment_date_gmt`
,`comment_content`, `comment_karma`, `comment_approved`, `comment_agent`
,`comment_type`, `comment_parent`, `user_id`)
VALUES (1, 1, 'Mr WordPress', ''
,'http://wordpress.org/', '', '2011-04-28 00:49:55', '2011-04-28 00:49:55'
,'Hi, this is a comment.<br />To delete a comment,
just log in and view the post's comments.
There you will have the option to edit or delete them.'
, 0, 'post-trashed', '', '', 0, 0 ) ;
MySQL said:
#1062 - Duplicate entry '1' for key 'PRIMARY'
The original data is still in the database.
If you were working manually you'd send a UPDATE rather than INSERT query with the new values, but since you're doing a batch import, it may just be better to wipe the existing table clean before the import.
DELETE FROM `tblName`;
Be sure to back-up your data, first.
To avoid duplicates you have to use UPDATE instead of INSERT statements. To achieve this in phpMyAdmin, follow these steps:
Select your database in the tree.
OPTIONAL. Go to "Search" tab and search for string you want to replace in all tables. If string is found in several tables only, note their names. This will help to speed up process by updating only the tables which needs updating. This my be important if you have lot of data.
Go to "Export" tab.
In the "Export method:" select "Custom".
OPTIONAL. If you noted the tables which need updating in step 2 above, then in the "Table(s):" section, click "Unselect all" and then select only the tables which need to be updated.
Scroll down to "Data creation options" section, and in the drop
box labeled "Function to use when dumping data:" select "UPDATE"
(default is "INSERT").
Click "Go".
Open the downloaded SQL dump file.
IMPORTANT! Save the file with a new name for backup purposes before any changes are made.
Use Search & replace function of your editor to change what you want. Then save the file.
In phpMyAdmin go to "Import" tab.
In the "File to import:" section click the "Choose file" button and
browse for the edited file. Click GO
You are ready! To check if everything is OK, search the database second time (repeat step 2). You should not find any tables containing your old string.
If you're exporting, that means that the main content stays in the database. So, when you try to insert a new row with the same PRIMARY KEY, which are always UNIQUE, you'll get an error.
Solution: You must delete the row from the table that has the same comment_ID.
You must open the PHPMyAdmin and go your table page, and check the row with the ID you want. In this case is 1, which means that it is probabily in the first results page of your table listing. Just click on the red X which appears in the row.
This could also be done by SQL, which could be simple too.
DELETE FROM `wp_comments` WHERE `comment_ID` = 1 LIMIT 1
For this, just select your database in PHPMyAdmin and go to the SQL tab, and insert the code above in the text area.
Had the same problem and error number. Deleted the database, recreate with no tables, and import the changed export file worked for me.
The problem is related with your file - you are trying to create a DB using a copy - at the top of your file you will find something like this:
CREATE DATABASE IF NOT EXISTS *THE_NAME_OF_YOUR_DB* DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci;
USE *THE_NAME_OF_YOUR_DB*;
and I'm sure that you already have a DB with this name - IN THE SAME SERVER - please check, because you are trying to overwrite!! Just change the name OR (better) ERASE THIS LINE!
Since you already have that record there, you can just update the record rather than inserting. It would go something like this.
UPDATE `wp_comments`
SET 'comment_author_url' = 'YOUR NEW ADDRESS'
WHERE `comment_ID` = 1
Just update every instance of your old address using this method. You can search through all of all posts by saying "WHERE 'comment_author_url' = 'YOUR OLD ADDRESS'"
If all you want to do is replace your URL, I believe this is all you must do:
Update `wp_comments` Set
`comment_author_url` = 'http://wordpress.org/'
Where `comment_author` = 'Mr WordPress'
Just type the above SQL into PHPMyAdmin's SQL box and execute.
NOTE: First make sure you have a backup. And there's no need to do all that export and import stuff :)
Change to code to
INSERT .... (what you already have)
ON DUPLICATE KEY UPDATE;
This will fix your problem with a minimum of fuss, whilst still inserting new rows.