Table 'mdl___________' already exists

Table 'mdl___________' already exists

by Scott Brubaker -
Number of replies: 28
I am moving from Moodle 1.5 to 1.6 on the way to 1.7. Install seems to go well until the last step where I get serveral "table such and such already exists". Then finally getting a "data tables could NOT be set up successfully!" error. Does this over an over if I click continue. Suggestions?

I read the 1.6 FAQ, so I don't think its a matter of updating to UTF8 becuase that is done after the 1.6 setup is complete right?
Average of ratings: -
In reply to Scott Brubaker

Re: Table 'mdl___________' already exists

by dennis mr. -
try flushing the database...but do not flush the privileges
In reply to dennis mr.

Re: Table 'mdl___________' already exists

by Scott Brubaker -
I'm a real newbie so you'll have to feed me here. How do I do that? Do this before I start the update to 1.6 correct?
In reply to dennis mr.

Re: Table 'mdl___________' already exists

by Scott Brubaker -
dennis

can you tell me how to flush the tables in MySQL v5?
In reply to Scott Brubaker

Re: Table 'mdl___________' already exists

by Scott Brubaker -
I tried this using the command below. Still no luck.

mysqladmin -u root -p flush-tables
In reply to Scott Brubaker

Re: Table 'mdl___________' already exists

by Mauno Korpelainen -

Hi Scott,

I think that message "table ... already exists" means that you are trying to install a table that already exists. It is not the same as upgrading.

An easy way to upgrade is to rename old moodle folder, upload a new moodle folder, copy config.php from old moodle (and upgraded versions of blocks/modules/themes that are not with normal package) to new moodle folder and login as admin (in moodle 1.7 to Notifications)...

In reply to Mauno Korpelainen

Re: Table 'mdl___________' already exists

by Scott Brubaker -
This is the process I have been trying to perform. In fact I just tried again as a test to make sure. Same problem with tables already existing.
In reply to Scott Brubaker

Re: Table 'mdl___________' already exists

by Mariana Curado Malta -
Hi Scott,

I did a migration exactly the same and didn't have any problem, it went perfect!

Did you do it on the server or in a copy of the server?

If it was done in a copy how did you do the sqldump?

Mariana
In reply to Mariana Curado Malta

Re: Table 'mdl___________' already exists

by Scott Brubaker -
Currently this is on a test box with a copy of the Moodle data directory,Moodle folder, and an export and then import of the production server's Moodle database.

The command I use to dump the database on the production server was as fallows;

mysqldump -u root -p -C -Q -e -a moodle > moodlebak.sql

I then copied that .sql file over to our test box where I used the command below to import it into a blank Moodle database.

mysql -u root -p moodle < moodlebak.sql

Once I did this and had copied the Moodle directory (1.5+) and Moodle data directory to the test box I had a working clone of our production Moodle. Its here where I try to update to a newer version I have issues.
In reply to Scott Brubaker

Re: Table 'mdl___________' already exists

by Scott Brubaker -
anyone have any ideas? I can't come up with anything. I would really hate to be stuck at 1.5 forever.
In reply to Scott Brubaker

Re: Table 'mdl___________' already exists

by Scott Brubaker -
I thought I would start over just to double check and make sure I was fallowing the upgrade directions to the "t". Same thing. table already exists.

In reply to Scott Brubaker

Re: Table 'mdl___________' already exists

by Mauno Korpelainen -

I guess the problem is one of these:

- you have not copied config.php from previous moodle to new moodle folder and moodle tries to install a new version but can't do it because you have made mysql dump restore and tables already exist. To make a new install drop old tables first...

- you  have gone to install.php and not to your site (index.php)

- you have more than one moodle using the same database with same prefix mdl_ or you have wrong database settings in config.php

or something else...you could also drop those tables you get errors and restore them from mysql backup if it is necessary.

In reply to Mauno Korpelainen

Re: Table 'mdl___________' already exists

by Scott Brubaker -
I appreciate the suggestions.

I have copied the config.php file however
I am going to the admin login page
Double checked to ensure only the one moodle instance is using that database.
In reply to Scott Brubaker

Vast: Re: Table 'mdl___________' already exists

by Mauno Korpelainen -

OK. Have you tried to make a new moodle 1.6 install (without mysql dump and any previous data) and then backup some course from your moodle 1.5 (course admin menu Backup) and restore that course to your new moodle (course admin menu Restore)? Do you get errors that way?

In reply to Mauno Korpelainen

Re: Vast: Re: Table 'mdl___________' already exists

by Scott Brubaker -
I have done a clean install of each version from 1.5 up and they all work fine. I have not however done a backup from old and restore to new. I will give that a shot.
In reply to Scott Brubaker

Re: Vast: Re: Table 'mdl___________' already exists

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Hi Scott,
I have hunch, but I would like to confirm with the exact name of the table that appears in the first 'mdl__ already exists' message.
cheers
Gordon
In reply to Gordon Bateson

Re: Vast: Re: Table 'mdl___________' already exists

by Scott Brubaker -
Gordon, here are the errors I get when I try an upgrade. This was in trying to go from 1.5+ to 1.6.4.



1050: Table 'mdl_data' already exists
      

Error


(mysql): CREATE TABLE mdl_data_content ( id int(10) unsigned NOT NULL auto_increment, fieldid int(10) unsigned NOT NULL default '0', recordid int(10) unsigned NOT NULL default '0', content longtext NOT NULL default '', content1 longtext NOT NULL default '', content2 longtext NOT NULL default '', content3 longtext NOT NULL default '', content4 longtext NOT NULL default '', PRIMARY KEY (id)) TYPE=MyISAM
1050: Table 'mdl_data_content' already exists
      

Error


(mysql): CREATE TABLE mdl_data_fields ( id int(10) unsigned NOT NULL auto_increment, dataid int(10) unsigned NOT NULL default '0', type varchar(255) NOT NULL default '', name varchar(255) NOT NULL default '', description text NOT NULL default '', param1 text NOT NULL default '', param2 text NOT NULL default '', param3 text NOT NULL default '', param4 text NOT NULL default '', param5 text NOT NULL default '', param6 text NOT NULL default '', param7 text NOT NULL default '', param8 text NOT NULL default '', param9 text NOT NULL default '', param10 text NOT NULL default '', PRIMARY KEY (id)) TYPE=MyISAM
1050: Table 'mdl_data_fields' already exists
      

Error


(mysql): CREATE TABLE mdl_data_records ( id int(10) unsigned NOT NULL auto_increment, userid int(10) unsigned NOT NULL default '0', groupid int(10) unsigned NOT NULL default '0', dataid int(10) unsigned NOT NULL default '0', timecreated int(10) unsigned NOT NULL default '0', timemodified int(10) unsigned NOT NULL default '0', approved tinyint(4) unsigned NOT NULL default '0', PRIMARY KEY (id)) TYPE=MyISAM
1050: Table 'mdl_data_records' already exists
      

Error


(mysql): CREATE TABLE mdl_data_comments ( id int(10) unsigned NOT NULL auto_increment, userid int(10) unsigned NOT NULL default '0', recordid int(10) unsigned NOT NULL default '0', content text NOT NULL default '', created int(10) unsigned NOT NULL default '0', modified int(10) unsigned NOT NULL default '0', PRIMARY KEY (id)) TYPE=MyISAM
1050: Table 'mdl_data_comments' already exists
      

Error


(mysql): CREATE TABLE mdl_data_ratings ( id int(10) unsigned NOT NULL auto_increment, userid int(10) unsigned NOT NULL default '0', recordid int(10) unsigned NOT NULL default '0', rating int(10) unsigned NOT NULL default '0', PRIMARY KEY (id)) TYPE=MyISAM
1050: Table 'mdl_data_ratings' already exists
      

Error


In reply to Scott Brubaker

Re: Vast: Re: Table 'mdl___________' already exists

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
The "data" module was added in Moodle 1.6, so I presume you had nothing in these tables. Therefore, you can safely delete all the "data_xxx" tables and try the upgrade again.

This will cure the "table already exists" errors for the "data" module. However, I suspect you will then get some other error or errors. Ususally the first error is the most revealing. Please copy it and paste it to this forum.

regards
Gordon
In reply to Gordon Bateson

Re: Vast: Re: Table 'mdl___________' already exists

by Scott Brubaker -
I removed any table starting with "mdl_data". Here is a capture of the errors I get when upgrading after doing so. There were some "Success" ones, but not enough to make it work. sad

(mysql): SELECT COUNT(*) FROM mdl_dialogue
1146: Table 'moodle.mdl_dialogue' doesn't exist
 
 
 
 

(mysql): CREATE TABLE `mdl_course_request` ( `id` int(10) unsigned NOT NULL auto_increment, `fullname` varchar(254) NOT NULL default '', `shortname` varchar(15) NOT NULL default '', `summary` text NOT NULL, `reason` text NOT NULL, `requester` int(10) NOT NULL default 0, PRIMARY KEY (`id`), KEY `shortname` (`shortname`) ) TYPE=MyISAM
1050: Table 'mdl_course_request' already exists
 
 
 

 

Error

(mysql): CREATE TABLE `mdl_course_allowed_modules` ( `id` int(10) unsigned NOT NULL auto_increment, `course` int(10) unsigned NOT NULL default 0, `module` int(10) unsigned NOT NULL default 0, PRIMARY KEY (`id`), KEY `course` (`course`), KEY `module` (`module`) ) TYPE=MyISAM
1050: Table 'mdl_course_allowed_modules' already exists
 
 
 

 

Error



(mysql): CREATE TABLE `mdl_stats_daily` ( `id` int(10) unsigned NOT NULL auto_increment, `courseid` int(10) unsigned NOT NULL default 0, `timeend` int(10) unsigned NOT NULL default 0, `students` int(10) unsigned NOT NULL default 0, `teachers` int(10) unsigned NOT NULL default 0, `activestudents` int(10) unsigned NOT NULL default 0, `activeteachers` int(10) unsigned NOT NULL default 0, `studentreads` int(10) unsigned NOT NULL default 0, `studentwrites` int(10) unsigned NOT NULL default 0, `teacherreads` int(10) unsigned NOT NULL default 0, `teacherwrites` int(10) unsigned NOT NULL default 0, `logins` int(10) unsigned NOT NULL default 0, `uniquelogins` int(10) unsigned NOT NULL default 0, PRIMARY KEY (`id`), KEY `courseid` (`courseid`), KEY `timeend` (`timeend`) )
1050: Table 'mdl_stats_daily' already exists
 
 
 

 

Error


(mysql): CREATE TABLE mdl_stats_weekly ( `id` int(10) unsigned NOT NULL auto_increment, `courseid` int(10) unsigned NOT NULL default 0, `timeend` int(10) unsigned NOT NULL default 0, `students` int(10) unsigned NOT NULL default 0, `teachers` int(10) unsigned NOT NULL default 0, `activestudents` int(10) unsigned NOT NULL default 0, `activeteachers` int(10) unsigned NOT NULL default 0, `studentreads` int(10) unsigned NOT NULL default 0, `studentwrites` int(10) unsigned NOT NULL default 0, `teacherreads` int(10) unsigned NOT NULL default 0, `teacherwrites` int(10) unsigned NOT NULL default 0, `logins` int(10) unsigned NOT NULL default 0, `uniquelogins` int(10) unsigned NOT NULL default 0, PRIMARY KEY (`id`), KEY `courseid` (`courseid`), KEY `timeend` (`timeend`) )
1050: Table 'mdl_stats_weekly' already exists
 
 
 

 

Error


(mysql): CREATE TABLE mdl_stats_monthly ( `id` int(10) unsigned NOT NULL auto_increment, `courseid` int(10) unsigned NOT NULL default 0, `timeend` int(10) unsigned NOT NULL default 0, `students` int(10) unsigned NOT NULL default 0, `teachers` int(10) unsigned NOT NULL default 0, `activestudents` int(10) unsigned NOT NULL default 0, `activeteachers` int(10) unsigned NOT NULL default 0, `studentreads` int(10) unsigned NOT NULL default 0, `studentwrites` int(10) unsigned NOT NULL default 0, `teacherreads` int(10) unsigned NOT NULL default 0, `teacherwrites` int(10) unsigned NOT NULL default 0, `logins` int(10) unsigned NOT NULL default 0, `uniquelogins` int(10) unsigned NOT NULL default 0, PRIMARY KEY (`id`), KEY `courseid` (`courseid`), KEY `timeend` (`timeend`) )
1050: Table 'mdl_stats_monthly' already exists
 
 
 

 

Error


(mysql): CREATE TABLE mdl_stats_user_daily ( `id` int(10) unsigned NOT NULL auto_increment, `courseid` int(10) unsigned NOT NULL default 0, `userid` int(10) unsigned NOT NULL default 0, `roleid` int(10) unsigned NOT NULL default 0, `timeend` int(10) unsigned NOT NULL default 0, `statsreads` int(10) unsigned NOT NULL default 0, `statswrites` int(10) unsigned NOT NULL default 0, `stattype` varchar(30) NOT NULL default '', PRIMARY KEY (`id`), KEY `courseid` (`courseid`), KEY `userid` (`userid`), KEY `roleid` (`roleid`), KEY `timeend` (`timeend`) )
1050: Table 'mdl_stats_user_daily' already exists
 
 
 

 

Error


(mysql): CREATE TABLE mdl_stats_user_weekly ( `id` int(10) unsigned NOT NULL auto_increment, `courseid` int(10) unsigned NOT NULL default 0, `userid` int(10) unsigned NOT NULL default 0, `roleid` int(10) unsigned NOT NULL default 0, `timeend` int(10) unsigned NOT NULL default 0, `statsreads` int(10) unsigned NOT NULL default 0, `statswrites` int(10) unsigned NOT NULL default 0, `stattype` varchar(30) NOT NULL default '', PRIMARY KEY (`id`), KEY `courseid` (`courseid`), KEY `userid` (`userid`), KEY `roleid` (`roleid`), KEY `timeend` (`timeend`) )
1050: Table 'mdl_stats_user_weekly' already exists
 
 
 

 

Error


(mysql): CREATE TABLE mdl_stats_user_monthly ( `id` int(10) unsigned NOT NULL auto_increment, `courseid` int(10) unsigned NOT NULL default 0, `userid` int(10) unsigned NOT NULL default 0, `roleid` int(10) unsigned NOT NULL default 0, `timeend` int(10) unsigned NOT NULL default 0, `statsreads` int(10) unsigned NOT NULL default 0, `statswrites` int(10) unsigned NOT NULL default 0, `stattype` varchar(30) NOT NULL default '', PRIMARY KEY (`id`), KEY `courseid` (`courseid`), KEY `userid` (`userid`), KEY `roleid` (`roleid`), KEY `timeend` (`timeend`) )
1050: Table 'mdl_stats_user_monthly' already exists
 
 
 

 

Error

(mysql): ALTER TABLE mdl_course_request ADD password VARCHAR(50) DEFAULT '0' not null
1060: Duplicate column name 'password'
 
 
 

 

Error

(mysql): CREATE TABLE mdl_post ( `id` int(10) unsigned NOT NULL auto_increment, `userid` int(10) unsigned NOT NULL default '0', `courseid` int(10) unsigned NOT NULL default'0', `groupid` int(10) unsigned NOT NULL default'0', `moduleid` int(10) unsigned NOT NULL default'0', `coursemoduleid` int(10) unsigned NOT NULL default'0', `subject` varchar(128) NOT NULL default '', `summary` longtext, `content` longtext, `uniquehash` varchar(128) NOT NULL default '', `rating` int(10) unsigned NOT NULL default'0', `format` int(10) unsigned NOT NULL default'0', `publishstate` enum('draft','site','public') NOT NULL default 'draft', `lastmodified` int(10) unsigned NOT NULL default '0', `created` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `id_user_idx` (`id`, `userid`), KEY `post_lastmodified_idx` (`lastmodified`), KEY `post_subject_idx` (`subject`) ) TYPE=MyISAM COMMENT='New moodle post table. Holds data posts such as forum entries or blog entries.'
1050: Table 'mdl_post' already exists
 
 
 

 

Error


(mysql): CREATE TABLE mdl_tags ( `id` int(10) unsigned NOT NULL auto_increment, `type` varchar(255) NOT NULL default 'official', `userid` int(10) unsigned NOT NULL default'0', `text` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT ='tags structure for moodle.'
1050: Table 'mdl_tags' already exists
 
 
 

 

Error


(mysql): CREATE TABLE mdl_blog_tag_instance ( `id` int(10) unsigned NOT NULL auto_increment, `entryid` int(10) unsigned NOT NULL default'0', `tagid` int(10) unsigned NOT NULL default'0', `groupid` int(10) unsigned NOT NULL default'0', `courseid` int(10) unsigned NOT NULL default'0', `userid` int(10) unsigned NOT NULL default'0', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT ='tag instance for blogs.'
1050: Table 'mdl_blog_tag_instance' already exists
 
 
 

 

Error

(mysql): ALTER TABLE mdl_post ADD module VARCHAR(20) DEFAULT '' not null AFTER `id`
1060: Duplicate column name 'module'
 
 
 

 

Error


(mysql): ALTER TABLE mdl_post ADD INDEX post_module_idx (module)
1061: Duplicate key name 'post_module_idx'
 
 
 

 

Error



(mysql): ALTER TABLE mdl_blog_tag_instance ADD timemodified INTEGER(10) unsigned DEFAULT '0' not null AFTER `userid`
1060: Duplicate column name 'timemodified'
 
 
 

 

Error


(mysql): ALTER TABLE mdl_blog_tag_instance ADD INDEX bti_entryid_idx (entryid)
1061: Duplicate key name 'bti_entryid_idx'
 
 
 

 

Error


(mysql): ALTER TABLE mdl_blog_tag_instance ADD INDEX bti_tagid_idx (tagid)
1061: Duplicate key name 'bti_tagid_idx'
 
 
 

 

Error

(mysql): ALTER TABLE mdl_tags ADD INDEX tags_typeuserid_idx (type(20), userid)
1061: Duplicate key name 'tags_typeuserid_idx'
 
 
 

 

Error


(mysql): ALTER TABLE mdl_tags ADD INDEX tags_text_idx(text(255))
1061: Duplicate key name 'tags_text_idx'
 
 
 

 

Error


In reply to Scott Brubaker

Re: Vast: Re: Table 'mdl___________' already exists

by Scott Brubaker -
after that long list of errors I can still click "continue" doing so will get me past two more screens before giving this error.

(mysql): CREATE TABLE mdl_lams ( id int(10) unsigned NOT NULL auto_increment, course int(10) unsigned NOT NULL default '0', name varchar(255) NOT NULL default '', introduction text NOT NULL default '', learning_session_id bigint(20) default '0', timemodified int(10) unsigned NOT NULL default '0', PRIMARY KEY (id), KEY course (course))COMMENT='LAMS activity'
1050: Table 'mdl_lams' already exists
      

Error

lams tables could NOT be set up successfully!
In reply to Scott Brubaker

Re: Vast: Re: Table 'mdl___________' already exists

by Heather P -
Hi

you have what looks to me similar issues as I did when I tried to upgrade (have a look here http://moodle.org/mod/forum/discuss.php?d=62812 )
Ken Wilson kindly suggested turning strict mode off on the database before running the upgrade. Worked for me.
In reply to Heather P

Re: Vast: Re: Table 'mdl___________' already exists

by Scott Brubaker -
I just gave it a shot by turning off strict mode. sad No luck.

The command I used was...
SELECT @@global.sql_mode;
In reply to Scott Brubaker

Re: Vast: Re: Table 'mdl___________' already exists

by Heather P -
Hi
I know it is a bit after your posting but I was just checking my notes and I have a set of speech marks in my command line that you don't. I don't know if it will make any difference or not. I've also just realised as I type that you have used a select statement. Select statements just look at data it won't make any changes to it. You need:-

SET@@global.sql_mode=";

Hope it isn't too late. Alternatively if it is a fresh install one of the options in the install process is to run with strict mode off.


In reply to Heather P

Re: Vast: Re: Table 'mdl___________' already exists

by Scott Brubaker -
Thanks for your input. When I try the command you listed above I get the fallowing. We use phpMyAdmin to admin our MySQL.

Error

There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem

ERROR: Unclosed quote @ 21
STR: "
SQL: SET@@global.sql_mode="


SQL query:

SET@@global.sql_mode="

MySQL said: Documentation
#1064 - 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 '"' at line 1
In reply to Scott Brubaker

Re: Vast: Re: Table 'mdl___________' already exists

by Scott Brubaker -
silly me, it was a typo issue. the command uses two parentheses not a single quote. however, it still has not corrected my duplicate table issues.
In reply to Scott Brubaker

Re: Vast: Re: Table 'mdl___________' already exists

by Richard Enison -

SB,

I believe the typo was in HP's post. The character before the semicolon is a double quote but it should have been two single quotes (not two parentheses). Maybe two double quotes would work also, I'm not sure; but it definitely should be two quote marks in any case, not one.

RLE

In reply to Scott Brubaker

Re: Table 'mdl___________' already exists

by Scott Brubaker -
I wanted to post the steps I am taking hopefully someone on the forum can point out what I’m doing wrong. It’s a new part process, move moodle to a new server box then upgrade to newest stable version.


Moving Moodle

On Old Server:

  1. Dump MySQL moodle database with the command below
    1. Mysqldump –u root –p –C –Q –e –a moodle > moodlebackup.sql

  2. Copy moodle data directory, moodle web folder, and moodlebackup.sql to new server

On New Server:

  1. Move moodledata folder to /moodledata
  2. Move moodle web folder to /srv/www/htdocs/moodle
  3. Grant needed rights to moodle data folder and moodle web folder
  4. Import moodleback.sql into newly created blank moodle database using command below.
    1. Mysql –u root –p moodle < /moodlebackup.sql

  5. Edit config.php on new server to show new address. Change http://oldserver.company.com to http://newserver.company.com/

On Workstation:

  1. Access Moodle on New server. All is working correctly. Moodle moved, and all is good.

Updating Moodle

On New Server:

 1. Rename moodle (v1.5.4+) web folder to moodle.bak.

 2. Download Moodle 1.6 and extract to /srv/www/htdocs/

 3. Copy config.php from moodle.bak to /srv/www/htdocs/moodle

On Workstation:

  1. Access moodle website and login as admin user

 2. Get message about “new version” and click yes to continue the update process.

 3. Get the errors and problem with update as posted in this thread.