Run Username SQL Query from WordPress Child Theme Functions File

There are many ways you can achieve this… In your instance, as you pointed out $wpdb, here is the possible ways you can achieve this:

1. Use $wpdb::query

You can run this query directly using $wpdb’s query method as:

add_action("init", "username_query")
function username_query(){
    global $wpdb;

    $prefix  = $wpdb->prefix;

    $query   = "UPDATE `{$prefix}wp_users` SET `user_login`= 'new-admin-name-here' WHERE `user_login`='old-admin-name-here'";

    $results = $wpdb->query( $query );

    if( $results === false ){
        return "Error updating admin";
    }

    return "Admin username updated";
}

2. Use $wpdb::update

You can also use $wpdb’s update method to run your query as in below example

add_action("init", "username_query")
function username_query(){
    global $wpdb;

    $updated_rows = $wpdb->update(
                                  "wp_users", 
                                  array( "user_login" => "new_admin_name_here" ), 
                                  array( "user_login" => "old_admin_name_here" ),
                                  array( "%s" ),
                                  array( "%s")
                                );

   if ( $updated_rows === false ){
        return "Error updating admin";
   }

   return "Admin username updated";

}