The aim of this paper is to present discrete stochastic approximation algorithms that adaptively optimize the spreading codes of users in a CDMA system employing linear MMSE receivers. The proposed algorithm is able to adapt to slowly time-varying channel conditions. One of the most important properties of the algorithm is its self-learning capability - it spends most of the computational effort at the global optimizer of the objective function. A tracking analysis of the adaptive algorithms is presented together with mean square convergence. An adaptive-step-size algorithm is also presented for optimally adjusting the step size based on the observations.