The following content is based on the CentOS 6.0 operating system, and the MySQL installation version is v5.1.59. The following describes how to compile and install MySQL through commands.
 
Compile and install mysql
 
Cd/usr/local/src
 
Tar zxvf mysql-5.1.59.tar.gz
 
Cd mysql-5.1.59
 
. /Configure -- prefix =/usr/local/mysql -- localstatedir =/usr/local/mysql/data/-- with-mysqld-ldflags =-all-static -- with-client-ldflags =-all-static -- with-unix-socket-path =/tmp/mysql. sock -- with-shared -- without-debug -- with-extra-charsets = all -- without-embedded-server -- enable-profiling -- enable-encryper -- enable-thread-safe-client -- with-server-suffix =-community -- with-extra-charset = utf8, gbk
 
Make
 
Make install
 
Note: During the make compilation process, if you see the following line on the screen, which is stuck there, you will not be able to get through for a long time. Do not think it is a compilation error or the server
Stuck. You only need to stick to it. wait patiently for a few minutes and the compilation will be successful! Mysql compilation and installation tells us that everything will succeed if you stick to it!
Make [4]: Entering directory '/usr/local/src/mysql-5.1.59/mysql-Test'
 
Groupadd mysql # Add a mysql Group
 
Useradd-g mysql-s/bin/false # create a user mysql and add it to the mysql group. mysql users are not allowed to log on directly to the system.
 
Chown-R root/usr/local/mysql/# allow root access
 
Chgrp-R mysql/usr/local/mysql/# Allow mysql group access
 
Cd/usr/local/mysql/# enter the mysql installation directory
 
Cp/usr/local/mysql/support-files/mysql. server/etc/rc. d/init. d/mysqld # Add Mysql to the system to start
 
Cp/usr/local/mysql/support-files/my-medium.cnf/etc/my. cnf # copy the configuration file (Note: The/etc directory contains my by default. cnf, directly overwrite it)
 
Chmod 755/etc/init. d/mysqld # execution permission
 
Vi/etc/profile # Add the mysql service to the system environment variable:
 
Add the following line at the end
 
Export PATH = $ PATH:/usr/local/mysql/bin
 
The following two lines link the myslq library file to the default system location, so that you do not need to specify the mysql library file address when compiling software such as PHP.
 
Ln-s/usr/local/mysql/lib/mysql/usr/lib/mysql
 
Ln-s/usr/local/mysql/include/mysql/usr/include/mysql
 
/Usr/local/mysql/bin/mysql_install_db -- user = mysql & # generate mysql System Database
 
/Usr/local/mysql/bin/mysqld_safe -- user = mysql & # Start mysql
 
/Etc/rc. d/init. d/mysqld start # start
 
Chkconfig mysqld on # Add to startup
 
Shutdown-r now # restart the system. Wait until the system is restarted and continue to perform the following operations on the terminal command line.
 
Mysql_secure_installation # Set the Mysql password
 
Press Y to enter the password twice as prompted.
 
Or directly change the password/usr/local/mysql/bin/mysqladmin-u root-p password "123456" # change the password
 
Service mysqld restart # restart
 
At this point, mysql installation is complete!