Skip to content
General Revolution Evolution Add-ons International
Login | Register | MODX.com
MODX Open Source Content Management System, Framework, Platform and More.
Find a Partner | Hosts + SaaS | Jobs | Donate
  • RegisterSign Up with the MODX Community
  • LoginUse Your MODX.com Account
  • MODX Community Forums
  • General
  • Tips & Tricks
  •  
  • How to rename table names after installation#

  • 8439
    89

    ed Reply #1, 5 years, 7 months ago

    Reply
    • Link to this post#1
    Kind of obvious but may help some people as I couldn't find anything in the manager interface to do this. Long after installation I discovered I wanted multiple modx sites to share the same database. The obvious way is to give each site a unique prefix for the table names, I chose to use the company name. Trouble is the first one had prefix 'modx_' and I wanted to change it for tidyness.

    So my database name was modx and the database owner was modx, using the mysql tee command I listed all the tables to a text file.
    mysql -u modx -p modx
    give password
    tee tempfile;
    show tables;
    \q
    I edited tempfile to remove noise characters and create a sql script to rename the tables

    my approach was to put a procedure at the top like
    foo() {
    echo RENAME OLDPFX_$1 TO NEWPFX_$1 ';'
    }
    then globally replace all occurrences of OLDPFX_ to 'foo '
    exit the editor and run the script saving the output
    sh tempfile >rename.sql
    then use mysql to do the renames
    mysql -u modx -p modx
    \. rename.sql
    \q
    Finally edit manager/includes/config.inc.php to change the table prefix to NEWPFX_

    Ed


  • 25663
    12,071


    Ryan Thrash

    MODX Co-Founder & Leader of Awesomeness




    MODX Revolution

    Your Content, Your Way.


    Issues | Documentation | Git the Source


    Need help? Help us help you.


    rthrash Reply #2, 5 years, 7 months ago

    Reply
    • Link to this post#2
    Very cool Ed, and thanks!


  • 8439
    89

    ed Reply #3, 5 years, 7 months ago

    Reply
    • Link to this post#3
    Just a quick follow up on this. My client's hosting service does weekly backups and in the event of disaster for one site and no other backup we'd have to roll back to the previous snapshot and corresponding database. This is obviously much more troublesome if multiple clients are sharing a single mysql database because you'd want to restore one set of tables only and they would restore the whole database.

    On reflection having multiple sites share a database is a poor idea unless e.g. you are constrained on the number of databases you can have. When planning database sharing, consider backups and restores.

    Ed


  • 9207
    1,899
    Hosting and Dev stuff: http://fireproofsocks.com/
    Articles and Reviews: http://tipsfor.us/

    Everett Reply #4, 2 years, 7 months ago

    Reply
    • Link to this post#4
    My two tangential thouhgts:

    1. Be careful about listing the "mysql" command the way you did: "mysql -u modx -p modx" note that this would mean that your password was actually preceded by a space. It took me a long time to figure that out. More correct would be "mysql -u modx -pmodx" (note the absence of a space).

    2. Yes, use separate databases for separate purposes. The only reason the prefix option is available is for overly-restrictive hosts. It's just like using separate folders to contain separate files. Organize organize organize...


  • 2449
    11

    austin Reply #5, 1 year, 11 months ago

    Reply
    • Link to this post#5
    It's also important to note that if your SQL isn't running you'll need:

    RENAME TABLE.. not just RENAME


  • 29423
    2
    Techno Travel - Medic Room - Trade Martes

    techicore Reply #6, 1 year, 10 months ago

    Reply
    • Link to this post#6
    great thanks
    i need this information


  • 25309
    1
    Mike Geary
    Avis Robot Menager
    Avis Centrale Vapeur
    Tout Sur Les Abdominaux

    Robot Menager Reply #7, 1 year, 5 months ago

    Reply
    • Link to this post#7
    Thanks a lot.
    I searched for a long time ... And find here the answer in 5 minutes!


  • 38944
    1
    underfloor heating
    central air conditioning and heating systems
    central heating

    carlern60 Reply #8, 2 months, 2 weeks ago

    Reply
    • Link to this post#8
    Great thanks..
    It really helps...

    central air conditioning and heating systems central heating





Actions

Login to Post

Other Support Options

To file a bug or make a feature request visit our issue tracker, or you can also purchase commercial support.

Love MODX?

If you build sites for a living with MODX or just love using it, why not give back?

Information

Posted in this thread:
Everettg_99, Robot Menager, austin, carlern60, ed, rethrash, techicore

 
Back to Top

MODX Global HQ

1333 N Stemmons Fwy, Ste 110
Dallas, TX 75207
United States

+1 (469) 777-MODX (6639)

The MODX Company

  • Contact
  • Media Center
  • Careers at MODX
  • Wall of Fame
  • The MODX Blog

Sponsors

SoftLayer Firehost: Secure Cloud Hosting

Stay Connected

Read our previous email newsletters.

Twitter Facebook Google+ LinkedIn github Feeds

Privacy Policy | Terms of Service | Pixels by AKTA Web Studio© 2005-2012 MODX. All rights reserved. Trademark Policy