Mariadb command questions
-
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: ```
UPDATEusers
SETuser_login
= '*olddomain',display_name
= '*olddomain' TO 'newdomain' -
@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:
-
Write SQL script that will use LOOP to iterate through all records in table users and then replace username with new username....
-
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 UPDATEIf you want more exact statements/formulas, give more detailed structure of your table and usernames
-