ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Mariadb command questions

    IT Discussion
    mariadb php
    2
    2
    403
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • WLS-ITGuyW
      WLS-ITGuy
      last edited by

      We're switching our domain name and because of that a few websites that we use have our old domain as the username/email address. Is there a way to SQL command that change without having to go into 700+ user accounts?

      Something like: ```
      UPDATE users SET user_login = '*olddomain', display_name = '*olddomain' TO 'newdomain'

      M 1 Reply Last reply Reply Quote 0
      • M
        Mario Jakovina @WLS-ITGuy
        last edited by Mario Jakovina

        @WLS-ITGuy If you wanted to say that old domain is part of usernames, and you want to change only that part of the usernames, there is no single SQL statement, but I see 2 solutions:

        1. Write SQL script that will use LOOP to iterate through all records in table users and then replace username with new username....

        2. Use spreadsheet calculator (Excel or similar) to prepare multiple simple SQL UPDATE statements:

        • Export table "users" (just necessary columns) and import it to Excel or similar _ - prepare new usernames in new column (use SUBSTITUTE() function in Excel)
        • prepare simple UPDATE command for each username (in new column in Excel) - you can use functions like SUBSTITUTE or CONCATENTE to prepare you UPDATE statements with your usernames from previous column, i.e. =CONCATENATE("UPDATE users SET username = '", ....
        • copy UPDATE statements from Excel and execute them

        I think secong approach (Excel) is much safer because you see results in spreadsheet before you execute UPDATEs.
        Always use WHERE clause when you use UPDATE

        If you want more exact statements/formulas, give more detailed structure of your table and usernames

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post