I have a .sql file and I want to load it into MySQL database. I don't know from which database (MySQL or MS-SQL) it was created.
Now, I am trying to import that file into MySQL database. It is showing errors while importing and executing that file.
Q1. So, my question is whether the .sql file generated from MySQL and MS-SQL are different?
Note: I am using SQLYog software (graphical interface for MySQL) for importing the file.
Here is the ERROR:
Query:
CREATE TABLE ads (
id bigint(20) NOT NULL auto_increment,
city_id int(11) NOT NULL,
type text collate utf8_bin NOT NULL,
town text collate utf8_bin NOT NULL,
address text collate utf8_bin NOT NULL,
price text collate utf8_bin NOT NULL,
info text collate utf8_bin NOT NULL,
link text collate utf8_bin NOT NULL,
hasImage int(11) NOT NULL,
language varchar(2) collate utf8_bin NOT NULL,
time_added varchar(255) collate utf8_bin NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1
Error occured at:2009-09-08 17:41:01
Line no.:35
Error Code: 1050 - Table 'ads' already exists
Query:
CREATE TABLE ads (
id bigint(20) NOT NULL auto_increment,
city_id int(11) NOT NULL,
type text collate utf8_bin NOT NULL,
town text collate utf8_bin NOT NULL,
address text collate utf8_bin NOT NULL,
price text collate utf8_bin NOT NULL,
info text collate utf8_bin NOT NULL,
link text collate utf8_bin NOT NULL,
hasImage int(11) NOT NULL,
language varchar(2) collate utf8_bin NOT NULL,
time_added varchar(255) collate utf8_bin NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1
Error occured at:2009-09-08 17:41:21
Line no.:35
Error Code: 1050 - Table 'ads' already exists
Query:
CREATE TABLE ads (
id bigint(20) NOT NULL auto_increment,
city_id int(11) NOT NULL,
type text collate utf8_bin NOT NULL,
town text collate utf8_bin NOT NULL,
address text collate utf8_bin NOT NULL,
price text collate utf8_bin NOT NULL,
info text collate utf8_bin NOT NULL,
link text collate utf8_bin NOT NULL,
hasImage int(11) NOT NULL,
language varchar(2) collate utf8_bin NOT NULL,
time_added varchar(255) collate utf8_bin NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1
Error occured at:2009-09-08 17:41:35
Line no.:35
Error Code: 1050 - Table 'ads' already exists
Query:
CREATE TABLE ads (
id bigint(20) NOT NULL auto_increment,
city_id int(11) NOT NULL,
type text collate utf8_bin NOT NULL,
town text collate utf8_bin NOT NULL,
address text collate utf8_bin NOT NULL,
price text collate utf8_bin NOT NULL,
info text collate utf8_bin NOT NULL,
link text collate utf8_bin NOT NULL,
hasImage int(11) NOT NULL,
language varchar(2) collate utf8_bin NOT NULL,
time_added varchar(255) collate utf8_bin NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1
Error occured at:2009-09-08 17:42:07
Line no.:35
Error Code: 1050 - Table 'ads' already exists
Query:
1 Stanford University 6700 http://www.orkut.co.in
.
.
.
The file extension ".sql" is essentially meaningless: it's just there so that you know what the file is. It will just be a plain text file containing SQL, which you can open in Notepad. Therefore, there's no special "mysql" or "sql server" extensions.
The errors you're getting there "Table 'ads' already exists" are because you're trying to create a table which already exists in the database. (Did you read the error?) You have a few options:
Change the SQL to this:
CREATE TABLE IF NOT EXISTS ads ( id bigint(20) ...
Change the SQL to this:
DROP TABLE IF EXISTS ads;
CREATE TABLE ads (id bigint(20) ...
Clear out all the tables in the DB first.
MySQL and Microsoft SQL Server do, unfortunately, implement different dialects of SQL. So, the answer to your question :
Q1. So, my question is whether the
.sql file generated from MySQL and
MS-SQL are different?
is "yes, quite possiby". However, the specific error you're showing appears to be due strictly to a "Create table" statement on line 35 being executed over and over and over again, and that can't depend on such dialect differences, so the causes have to be other ones (such as bugs or subtle format differences in what that "SQLYog" program, which I'm not familiar with, expects as its input).
It depends on which software exported this file. Also check in the file's header which software did it and analyze the syntax to determine where this file belongs to. Note also that SQL is microsoft sql server.
Yes. SQL varies greatly from database to database. While there is a SQL standard which most databases support much of, every database has numerous, incompatible nonstandard features and functions above and beyond that specified by the standard.
There are also many migration docs avaiable:
MSSQL => MySQL:
http://dev.mysql.com/tech-resources/articles/migrating-from-microsoft.html
MySQL => MSSQL:
http://technet.microsoft.com/en-us/library/cc966396.aspx
There are two obvious things in your CREATE TABLE statement that MSSQL doesn't support which jump out immediately:
ENGINE=InnoDB
AUTO_INCREMENT=1
Those are both MySQL-specific statements.
It looks like your script is being executed multiple times (as the line number where the error occurs is the same each time). The error also indicates that you're trying to define a table that already exists, which may be from the first time this script ran. You may want to look into how the script is being run to see why it may be executing multiple times.
The SQL itself looks fine for MySQL. It wouldn't run with SQL Server.
Related
I have removed users table in my database and imported another users table.
It show this error:
Error
SQL query:
CREATE TABLE `users` (
`id` int(11) UNSIGNED NOT NULL,
`user_group_id` int(11) UNSIGNED NOT NULL,
`gender` tinyint(1) DEFAULT NULL,
`first_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`last_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`national_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`birthday` date DEFAULT NULL,
`company` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`eco_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`national_id` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`address` text COLLATE utf8mb4_unicode_ci,
`post_code` varchar(255) COLLATE utf8mb4_unicode_ci[...]
MySQL said: Documentation
#1215 - Cannot add foreign key constraint
My framwork is Laravel 5.6, PHP 7.2
How to solve this issue?
When you are working with migrations, you have to make every change in database through migrations. You can make changes in the existing users_table migration file. You can drop/add column/table using artisan command. Migrations in Laravel can do every interaction with the database. Take your time to go thorugh all the basics of migrations if you don't know:
Laravel Migrations
Use migration in laravel. It is better that way and check the migration field in your table. May be the previous migrations will still be there
When trying to import database
Error
SQL query:
CREATE TABLE `wp_ihrss_plugin` (
`Ihrss_id` int(11) NOT NULL,
`Ihrss_path` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`Ihrss_link` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`Ihrss_target` varchar(50) NOT NULL,
`Ihrss_title` varchar(500) NOT NULL,
`Ihrss_order` int(11) NOT NULL,
`Ihrss_status` varchar(10) NOT NULL,
`Ihrss_type` varchar(100) NOT NULL,
`Ihrss_extra1` varchar(100) NOT NULL,
`Ihrss_extra2` varchar(100) NOT NULL,
`Ihrss_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=MyISAM DEFAULT CHARSET=utf8
MySQL said: Documentation
#1050 - Table 'wp_ihrss_plugin' already exists
and 5 more tables ; when try to drop one it show that there is another one
One possible approacj to deal with this would be to drop and recreate the object. For instance:
DROP TABLE IF EXISTS `foo`;
CREATE TABLE `foo` ( ... );
There are some duplicate tables present in your database dump.
Check the sql file from which you are trying to import
So I had a set of tables working on an older version of MySQL, however on this new version the tables it exported give a syntax error.
CREATE TABLE `joblistings` (
`jobid` int(11) NOT NULL AUTO_INCREMENT COLLATE utf8_unicode_ci NOT NULL,
`id` varchar(255) NOT NULL,
`client` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`service` tinyint(1) COLLATE utf8_unicode_ci NOT NULL,
`firstline` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`city/town/village` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`county` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`postcode` varchar(9) COLLATE utf8_unicode_ci NOT NULL,
`daterequired` date(YYY-MM-DD) NOT NULL,
`timefrom` time(HH:MM),
`timeto` time(HH:MM),
PRIMARY KEY (`jobid`),
UNIQUE KEY `id` (`jobid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=10 ;
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 '(YYY-MM-DD) NOT NULL, `timefrom` time(HH:MM),
`timeto` time(HH:MM), PRIMARY ' at line 10
These 3 seem to be the problem, from what I understand, however I am not versed well enough in versions and changes to see a way of fixing this.
`daterequired` date(YYY-MM-DD) NOT NULL,
`timefrom` time(HH:MM),
`timeto` time(HH:MM),
Any help would be much appreciated, keeping this format is important for my system to function.
You cannot change the format of the date and time. It will be stored in the default format('YYYY-MM-DD HH:MM:SS'). You can refer the documentation for more details.
The SQL Fiddle Demo after setting it to default format.
If you want to get the output in some other format then you have to use the DATE_FORMAT() function to get it in your required format.
So i get an error when i try and use
SELECT views, keywords, title, url, thumbnail,
MATCH(keywords,title) AGAINST ('%$search_value%') AS relevance
FROM straight
WHERE MATCH (keywords,title) AGAINST ('%$search_value%')
ORDER BY relevance DESC
This is due to me not having FULLtext search enabled, but i cant seem to enable it. when i run the sql below:
ALTER TABLE straight ADD FULLTEXT(keywords, title)
i get this response:
MySQL returned an empty result set (i.e. zero rows). (Query took 3.8022 sec)
Then when trying to run the first query again i get the failed
#1191 - Can't find FULLTEXT index matching the column list
I can't tell why it's not registering. Any help would be great.
Thanks!
Edit:
My tabel:
CREATE TABLE `straight` (
`url` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
`title` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
`keywords` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
`production` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
`categories` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
`views` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
`likes` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
`length` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
`thumbnail` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`date` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL,
UNIQUE KEY `url` (`url`),
FULLTEXT KEY `url_2` (`url`,`title`,`keywords`,`production`,
`categories`,`views`,`likes`,`length`,`thumbnail`,`date`
), ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
You need a FULLTEXT index that matches, exactly, the columns upon which you want to search. The FULLTEXT index you have has more columns than you need.
Try adding the one you mentioned.
ALTER TABLE straight ADD FULLTEXT(keywords, title)
Then look at the table definition and make sure it's there.
I have the member table which has 9 fields: id,email,... so on.
member_type is the 8th field
The 8th field is always converted to decimal, no matter what name it is or what type it is.
Here is some experimenting I have done:
irb(main):010:0> Member.all()[0].attributes
=> {"created_date"=>nil, "email"=>"tanixxx#yahoo.com", "id"=>1, "is_admin"=>0, "
member_type"=>#<BigDecimal:4f87ce0,'0.0',4(8)>, "name"=>"tanin", "password"=>"3c
f622832f10a313cb74a59e6032f115", "profile_picture_path"=>"aaaaa", "status"=>"APP
ROVED"}
Please notice :member_type, which is the 8th field.
Now if I query only some fields, the result is correct:
irb(main):007:0> Member.all(:select=>"member_type,email")[0].attributes
=> {"email"=>"tanixxx#yahoo.com", "member_type"=>"GENERAL"}
I think there must be a bug in ActiveRecord.
Here is some more experiment. I have added "test_8th_field" to be the 8th field and I got this:
irb(main):016:0> Member.all[0].attributes
=> {"created_date"=>nil, "email"=>"tanixxx#yahoo.com", "id"=>1, "is_admin"=>0, "
member_type"=>"GENERAL", "name"=>"tanin", "password"=>"3cf622832f10a313cb74a59e6
032f115", "profile_picture_path"=>"aaaaa", "status"=>"APPROVED", "test_8th_field
"=>#<BigDecimal:30c87f0,'0.0',4(8)>}
The 8th field is a BigDecimal (it is a text field in MySQL, though). But the member_type field is amazingly correct this time.
I don't know what is wrong with the number 8...
Please help me.
Here is my schema dump, including test_8th_field:
CREATE TABLE IF NOT EXISTS `members` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`profile_picture_path` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`status` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`is_admin` int(11) NOT NULL,
`test_8th_field` text COLLATE utf8_unicode_ci NOT NULL,
`member_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'GENERAL',
`created_date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ;
I have solved it. It turns out that the MySql binary library does not match the version for the MySql database itself.