Updating mysql email field without affecting - mysql

Recently I mass added customers details. However, my client just updated me that the email address format is wrong.
For example: The previous given email was abc#mail.com. However, I have to edit to this to abc#me.mail.com.
Is there any way I can check for #mail.com and change it to #me.mail.com?

update your_table
set email = replace(email, '#mail.com', '#me.mail.com')
where email like '%#mail.com'

Related

Modify exiting email instead of making a new one

I should modify the existing email by discarding everything after # from the existing email address (or taking only the initial part of the email address to the # sign) and adding iths.edu.rs.
This one is wrong because it creates new email.
SELECT fname,lname,email,CONCAT(LOWER(fname),'.',LOWER(lname), '#iths.edu.rs') AS 'new_email'
FROM employee
WHERE
(LEFT(fname,1)='s' OR LEFT(lname,1)='s')
AND email IS NOT NULL
This is what I get
These are expected results
I think that you want to update the table:
UPDATE employee
SET email = CONCAT(LOWER(fname),'.',LOWER(lname), '#iths.edu.rs')
WHERE (LEFT(fname,1)='s' OR LEFT(lname,1)='s') AND email IS NOT NULL
I'm not sure about the condition:
(LEFT(fname,1)='s' OR LEFT(lname,1)='s')
but I left it there because you use it in your code.
I ended up using this to show only people whose emails have been changed. This was my task.
UPDATE employee
SET email = CONCAT(LOWER(fname),'.',LOWER(lname), '#iths.edu.rs')
WHERE (LEFT(fname,1)='s' OR LEFT(lname,1)='s') AND email IS NOT NULL;
SELECT fname,lname,email
FROM employee
WHERE (LEFT(fname,1)='s' OR LEFT(lname,1)='s') AND email IS NOT NULL

Update Column from another column in same table

we need to update our mail addresses in a table, because we have a new domain-part. The local-part remains untouched
In the table is a column for Name, Surname and Mail. (And other columns which are not important).
We want it to look like this in the end:
Name Surname Mail
Test Name Test.Name#newdomain.com
Test2 Name2 Test2.Name2#newdomain.com
But while trying to do so we broke it and now the mail column only shows the new domain. We used the following code:
update table
set mail = Replace('olddomain.com','newdomain.com')
where mail LIKE '%olddomain.com'
So now we need to restore the mail column and add the new domain-part. Any help?
I'm surprised this works. Normally, replace() takes three arguments:
set mail = Replace(mail, 'olddomain.com', 'newdomain.com')
I might suggest that you include the # in the logic as well.
replace() takes three arguments
update table
set mail = Replace(mail,'#olddomain.com','#newdomain.com')
where mail LIKE '%olddomain.com'

use csv list to update a MySQL field

I have csv list which contains bounced emails addresses, one per line.
example1#example1.com
example2#example2.com
example3#example2.com
...
example700#example12.com
I need to change the user_state for each of these email to 'email_bounce'.
With the following SQL query i can do the changes using one email address at a time.
UPDATE xf_user SET user_state = 'email_bounce' WHERE email = 'example1#example1.com';
UPDATE xf_user SET user_state = 'email_bounce' WHERE email = 'example2#example2.com';
and so on
I made a copy of the DB where i would like to do a dry run but i have no idea how to automate this SQL query to go through all the emails in my csv.

MySQL change email domains

I am using benkeens open source script (http://benkeen.github.io/generatedata/) to generate random data. The problem is it gives weird email domains within the database. The code I was using to change the domains is:
UPDATE emails
SET email_address = CONCAT(LEFT(email_address, INSTR(column, '#')), 'google.com')
WHERE email LIKE '%#magnamalesuada.org%';
The only issue is, there are literally a hundred different domains being generated. Is it possible to change domain names to google, yahoo, hotmail, etc in a more efficient way?
Assuming you have an id column, you could use the % operator to divide your rows in groups, for example in 3:
UPDATE emails
SET email_address = CONCAT(LEFT(email_address, INSTR(column, '#')), 'google.com')
WHERE id%3=0;
UPDATE emails
SET email_address = CONCAT(LEFT(email_address, INSTR(column, '#')), 'yahoo.com')
WHERE id%3=1;
UPDATE emails
SET email_address = CONCAT(LEFT(email_address, INSTR(column, '#')), 'hotmail.com')
WHERE id%3=2;

How do I change a user's Email address in MediaWiki

With access sysop and database access how do I change the Email address associated with a user?
The user table in the database has everything encoded as BLOBs. If I can decode and encode those values presumably I can just update user.user_email.
UPDATE user SET user_email='foo#bar.com' WHERE user_id=... should just work. However, if you need to also set the confirmed flag, see instructions here (replace the mwscript line with php maintenance/eval.php). If you need to set their email only so that they could reset their password, see https://www.mediawiki.org/wiki/Manual:Resetting_passwords
You can get a current list of users and emails like this (i.e. decode):
SELECT Cast(user_name AS CHAR), Cast(User_Email AS CHAR) FROM user;
MaxSem's answer did not work for me, but here is a MediaWiki maintenance script (introduced in v1.27) that'll do the trick: https://www.mediawiki.org/wiki/Manual:ResetUserEmail.php
Go to the base directory of your wiki, and type something like this:
php maintenance/resetUserEmail.php uuuu new#email.address
to change user uuuu's email address to new#email.address. By default, this will change the user's password so that the user has to reset it, which can usually be done on the wiki website. You might need to add user name and password for database access, e.g.:
php maintenance/resetUserEmail.php --dbuser myuser --dbpass wordpass uuuu new#email.address