step 1 add this line (or a similar name) to make.conf PORTDIR_OVERLAY="/root/portage/dev-db/mysql" step 2 make the directory mkdir -p /root/portage/dev-db/mysql step 3 copy the ebuild cp /usr/portage/dev-db/mysql/mysql-5.0.19.ebuild /root/portage/dev-db/mysql step 4 - downloads source ebuild /usr/portage/dev-db/mysql/mysql-5.0.19.ebuild digest step 5 - unpack source ebuild /usr/portage/dev-db/mysql/mysql-5.0.19.ebuild unpack step 6 - find source code directory The source code should be unpacked in: /var/tmp/portage/mysql-5.0.19/work/mysql This directory will be listed in the output from the previous command cd to this directory step 7: start compile to run config, and kill the compilation Type this and kill it after a few minutes: ebuild /usr/local/portage/category/program/program-version.ebuild compile >& track you can use top, to see when gcc starts. Kill it after gcc starts. Optional step: rerun config with custom arguments Open track.txt in a text editor. The first line should be the call to config. Note that to call config yourself, you must add the double quotes ", back to any strings with white space. For example --comment=Compiled for Gentoo becomes --comment="Compiled for Gentoo" If you want to keep debugging information, then find which arguments control debugging, copy all of the arguments to a bash script, and rerun config. step 7: alter the source files under the main directory should be a diretory sql. It should cointain these files: lex.h item_create.h intem_func.h item_create.cc item_func.cc step 8: Add one line to lex.h that defines the function name in the sql_functions[] array. If the function prototype is simple (just takes zero, one, two or three arguments), you should in lex.h specify SYM(FUNC_ARGN) (where N is the number of arguments) as the second argument in the sql_functions[] array and add a function that creates a function object in item_create.cc. Take a look at "ABS" and create_funcs_abs() for an example of this. If the function prototype is complicated (for example, if it takes a variable number of arguments), you should add two lines to sql_yacc.yy. One indicates the preprocessor symbol that yacc should define (this should be added at the beginning of the file). Then define the function parameters and add an \u201citem\u201d with these parameters to the simple_expr parsing rule. For an example, check all occurrences of ATAN in sql_yacc.yy to see how this is for example, cumnorm takes one argument, so this line is added to lex.h: { "CUMNORM", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cumnorm)}, step 9: In item_func.h, declare a class inheriting from the appropriate parent class; The function cumnorm is similar to exp, so this is a good parent/child inheritance: < class Item_func_cumnorm :public Item_dec_func < { < public: < Item_func_cumnorm(Item *a) :Item_dec_func(a) {} < double val_real(); < const char *func_name() const { return "cumnorm"; } < }; step 10: In item_func.cc, add one of the following declarations, depending on whether you are defining a numeric or string function double Item_func_newname::val() longlong Item_func_newname::val_int() String *Item_func_newname::Str(String *str) For example, the function cumnorm is similar to exp, so we can use exp as a template and we get: double Item_func_cumnorm::val_real() { DBUG_ASSERT(fixed == 1); double value= args[0]->val_real(); if ((null_value=args[0]->null_value)) return 0.0; /* purecov: inspected */ return cumulative_normal_distribution_function(value); } This is where we do the programming logic also. Note the call to cumulative_normal_distribution_function double normal_distribution_function( double x) { return exp( -x*x / 2) / sqrt( 2 * 3.141592653589793238462643383); } double cumulative_normal_distribution_function( double x) { double cdf; if (x < 0) { cdf = 1 - cumulative_normal_distribution_function( -x); } else { double b[6] = { 0, .319381530, -.356563782, 1.781477937, -1.821255978, 1.330274429}; double p = .2316419; double t = 1 / (1+p*x), tpoly; double poly = 0, Z; int i; tpoly = t; for (i=1; i<=5; i++) { poly += b[i] * tpoly; tpoly *= t; } Z = normal_distribution_function( x); cdf = 1 - Z * poly; } return cdf; } double Item_func_cumnorm::val_real() { DBUG_ASSERT(fixed == 1); double value= args[0]->val_real(); if ((null_value=args[0]->null_value)) return 0.0; /* purecov: inspected */ return cumulative_normal_distribution_function(value); } step 11: cd up one level, and run make step 12: run make install step 11: REBOOT THE SERVER !!!!!!!!!!!!!!!!