How to add a prefix to existing custom fields over MYSQL query?

important: backup your database first!

Assuming your table prefix is ‘wp_’, this query will change the custom field names:

update wp_postmeta set meta_key = 'booking_testfield' where meta_key = 'testfield';

NB: this also assumes that the custom field name is unique to your application, i.e. it isn’t used by another post type. If it is possible that another post type is using that field name, then you will need to change the update query to join wp_posts to wp_postmeta and filter on post_type also.

Edit: if you want to duplicate the data into new fields, use an insert query instead, like this:

insert into wp_postmeta(post_id, meta_key, meta_value)
    select post_id, concat('booking_', meta_key), meta_value
    from wp_postmeta
    where meta_key = 'testfield';

NB: this will duplicate the data once. If you already have some data with the new keys, you’ll get multiple values — add a subquery to eliminate those posts from the insert set.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)