2

I used Duplicator Pro to move my live site to a virtual host on WampServer on my Windows 11 Pro desktop. Everything works fine except for two recurring errors in the PHP_Error.log file:

[19-Feb-2023 16:15:21 UTC] WordPress database error Table ‘_prefix_e_events’ already exists for query CREATE TABLE _PREFIX_e_events ...

and

[19-Feb-2023 16:15:21 UTC] WordPress database error Duplicate key name ‘created_at_index’ for query ALTER TABLE _PREFIX_e_events ADD INDEX created_at_index (created_at) ...

Note that I changed the real prefix to "prefix".

I understand the error is caused by mixed case PREFIX/prefix in the commands. I added "lower_case_table_names = 2" to my.ini file, but then WampServer won't start with this error:

2023-02-22T15:59:25.510378Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('2') and data dictionary ('1').

I believe I need to re-initialize the server but I don't know how to do that. This post gives clear instructions how to do this in Linux.

Is re-initializing the server the correct solution? If so, does anyone know how to do this on Windows 11 with WampServer 3.3.1? If not, what are my next steps?

Other things I have tried, with no luck:

Installed the latest release of MySQL 8.0.32, edited my.ini file to add lower_case_table_names = 2, then launched WampServer and switched to the new version of MySQL. This generated the same error with mismatched server/data dictionary.

Launched phpMyAdmin and tried to change the lower_case_table_names setting from 1 to 2, but got an error that this variable is read only.

Changed the prefix to lower case in wp-config.php. This eliminated the errors but only worked until I logged out. I was unable to login had to restore the prefix to uppercase in wp-config.php and then logged back into WordPress and have the site function again.

user1191247
  • 10,808
  • 2
  • 22
  • 32
DarrylB
  • 23
  • 4

1 Answers1

0

The reason you were unable to login after changing the prefix is that user roles are cached in the options table.

Based on your errors above, it looks like you changed $table_prefix from _PREFIX_ to _prefix_. So, this is what I have used for the below UPDATE statements.

As well as changing $table_prefix, you need to update some values in the database:

UPDATE _prefix_usermeta
SET meta_key = REPLACE(meta_key, '_PREFIX_', '_prefix_')
WHERE BINARY meta_key LIKE '%\_PREFIX\_%';

UPDATE _prefix_options
SET option_name = REPLACE(option_name, '_PREFIX_', '_prefix_')
WHERE BINARY option_name LIKE '%\_PREFIX\_%';

It's possible that your events plugin is caching the old prefix in some other way. What plugin are you using?


Re-initialize MySQL on Windows

The following instructions are based on the following:

  • MySQL 8.0.32
  • MySQL windows service named MySQL80
  • Path to mysqld.exe: C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe
  • Path to my.ini: C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
  • Path to datadir: C:\ProgramData\MySQL\MySQL Server 8.0\Data
  1. Open cmd.exe as administrator
  2. Stop MySQL service
    net stop MySQL80
    
  3. Find and change, or add, "lower_case_table_names=2" in the [mysqld] section of your my.ini
  4. Move the current data directory
    move "C:\ProgramData\MySQL\MySQL Server 8.0\Data" "C:\ProgramData\MySQL\MySQL Server 8.0\Backup"
    
  5. Create new data directory
    mkdir "C:\ProgramData\MySQL\MySQL Server 8.0\Data"
    
  6. Initialize MySQL
    "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --initialize --lower_case_table_names=2 --console
    
  7. Make a note of the new temporary password generated by initialize
  8. Start MySQL service
    net start MySQL80
    
  9. Login to mysql using the new password (from step 7)
    mysql -uroot -p
    
  10. Set new password
    mysql> ALTER USER USER() IDENTIFIED BY 'your_new_root_password'
    
    or, if you want to have blank password:
    mysql> SET PASSWORD FOR root@localhost = '';
    
user1191247
  • 10,808
  • 2
  • 22
  • 32
  • Thank you for taking the time to assist me. The plugin is Elementor and the file is [db.php](https://pastebin.com/Rwj6XLDc). I don't use this functionality, my e_events table is always empty. I'd rather not change the database because I will need to export/import this back to my live site where case sensitivity matters. I'm uncertain what your suggested changes would do to my live site once that happens (I just don't have enough experience this subject matter). I'd appreciate it if you could provide the instructions to re-initialize the database. – DarrylB Feb 27 '23 at 14:44
  • For clarity, full error message:Duplicate key name ‘created_at_index’ for query ALTER TABLE _PREFIX_e_events ADD INDEX created_at_index (created_at) made by require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), do_action(‘template_redirect’), WP_Hook->do_action, WP_Hook->apply_filters, Elementor\Frontend->init, Elementor\Plugin->init_common, Elementor\Core\Common\App->init_components, Elementor\Core\Common\Modules\EventTracker\Module->__construct, Elementor\Core\Common\Modules\EventTracker\DB->__construct, Elementor\Core\Common\Modules\EventTracker\DB->add_indexes – DarrylB Feb 27 '23 at 15:05
  • I tried but I am unable to change my $table_prefix on my live site. Bluehost doesn't allow this. The prefix is also part of my username and is generated when the hosting was setup. Somehow Bluehost ties it all together and doesn't allow any changes. The path to my executable is: C:\wamp64\bin\mysql\mysql8.0.32\bin\mysql.exe. I user the username root with no password. – DarrylB Feb 27 '23 at 16:10
  • Bear with my inexperience. Thanks for your ongoing help. From services.msc, for service wampmysqld64, path to executable: c:\wamp64\bin\mysql\mysql8.0.32\bin\mysqld.exe wampmysqld64 For MariaDB (which I don't use): c:\wamp64\bin\mariadb\mariadb10.10.2\bin\mysqld.exe --defaults-file=c:\wamp64\bin\mariadb\mariadb10.10.2\.\my.ini wampmariadb64 So, should mine be: c:\wamp64\bin\mysql\mysql8.0.32\bin\mysqld.exe --defaults-file=c:\wamp64\bin\mysql\mysql8.0.32\my.ini wampmysqld64 Note the '.' in the MariaDB path does not exist in the folder structure. Possibly because it is not used? – DarrylB Feb 27 '23 at 17:36
  • Yes, the two `mysql8.0.32` paths. You will need to check the `datadir` specified in that `my.ini`. – user1191247 Feb 27 '23 at 17:45
  • 1
    Thank you for the detailed instructions. I'll edit them for my own paths and services and give it a shot. I'll report back soon with my results. – DarrylB Feb 27 '23 at 17:53
  • I followed the instructions using my own paths/locations, and I believe the server was re-initialized with lower_case_table_names=2 but I still get the same errors in the PHP_Error.log file. I believe it is re-initialized because I don't get any errors about lower_case_table_names settings for server ('2') and data dictionary ('1'). My steps in the next comment ... – DarrylB Feb 27 '23 at 20:03
  • My process: 1) exported database using phpMyAdmin, 2) exit Wamp, 3) add lower_case_table_names=2 to my.ini 3) at cmd prompt (as Administrator) I moved data folder & created data folder, 4) ran "c:\wamp64\bin\mysql\mysql8.0.32\bin\mysqld.exe" --defaults-file="c:\wamp64\bin\mysql\mysql8.0.32\my.ini" --initialize-insecure --lower_case_table_names=2 --console 5) started Wamp 6) in phpMyAdmin, created database and imported database from step 1. The site works fine, I've changed a few things that will write to the database and all is well, except the errors persist. I'm at a loss. – DarrylB Feb 27 '23 at 20:04
  • The table names in your dump from local will be based on the lowercase table names. Either use the previous export from your other environment or edit the prefix in your new dump file. Or, rename the newly reimported tables so they have capitalised PREFIX. – user1191247 Feb 27 '23 at 20:13
  • Thanks again for your help. You have answered my question and your solution has allowed me to re-initialize my server. I have new issues importing the live database using Duplicator Pro but they are out of the scope of this question. – DarrylB Feb 28 '23 at 03:03
  • I resolved the Duplicator Pro issues and have the site running with the changes in place. No more errors in the log file. Thanks again. Your help is much appreciated. – DarrylB Feb 28 '23 at 05:12
  • Glad you got there in the end. Please remember to accept the answer. – user1191247 Feb 28 '23 at 07:37