Install MySql in Linux-source code
1.hypothetical two source files: mysql-5.5.10.tar.gzand cmake-2.8.4.tar.gz
(1) install cmake first (after mysql5.5 is compiled through cmake)
[root@ rhel5 local]#tar -zxv -f cmake-2.8.4.tar.gz[root@ rhel5 local]#cd cmake-2.8.4[root@ rhel5 cmake-2.8.4]#./configure[root@ rhel5 cmake-2.8.4]#make[root@ rhel5 cmake-2.8.4]#make install
(2) Create the MySQL installation directory and database storage directory
[Root @ rhel5 ~] # Mkdir-P/usr/local/MySQL // install MySQL [root @ rhel5 ~] # Mkdir-P/usr/local/MySQL/Data // store the database
(3) create mysql users and user groups
[root@ rhel5~]groupadd mysql[root@ rhel5~]useradd -r -g mysql mysql
(4) install MySQL
[root@ rhel5 local]#tar -zxv -f mysql-5.5.10.tar.gz[root@ rhel5 local]#cd mysql-5.5.10[root@ rhel5 mysql-5.5.10]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/usr/local/mysql/data-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci
-DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1[root@ rhel5 mysql-5.5.10]#make[root@ rhel5 mysql-5.5.10]#make install
Parameter description:
-Dcmake_install_prefix =/usr/local/MySQL // installation directory
-Dinstall_datadir =/usr/local/MySQL/Data // database storage directory
-Ddefault_charset = utf8 // use the utf8 character
-Ddefault_collation = utf8_general_ci // check the character
-Dextra_charsets = All // install all extended character sets
-Denabled_local_infile = 1 // allow local data import
Note:
During re-compilation, you need to clear the old object file and cache information.
# Make clean
# Rm-F cmakecache.txt
# Rm-RF/etc/My. CNF
# Here you also need to install the download tool libncurses5-dev if it is ncurses-devel under RedHat. Bison must also be installed
2. Configuration
(1) Set Directory Permissions
[Root @ rhel5 ~] # Cd/usr/local/MySQL [root @ rhel5 MySQL] # chown-r root: MySQL. // set the owner of all files in the current directory to root and the group to MySQL [root @ rhel5 MySQL] # chown-r MYSQL: MySQL DATA
(2)
[Root @ rhel5 MySQL] # cp support-files/my-medium.cnf/etc/My. CNF // Add MySQL startup service to System Service
(3) create a table for the system database
[root@ rhel5 mysql]# cd /usr/local/mysql[root@ rhel5 mysql]# scripts/mysql_install_db --user=mysql
(4) set Environment Variables
[Root @ rhel5 ~] # Vi/root /. bash_profile In Path = $ path: $ home/bin Add the parameter: Path = $ path: $ home/bin:/usr/local/MySQL/bin: /usr/local/MySQL/lib [root @ rhel5 ~] # Source/root/. bash_profile
(5) manually start MySQL
[Root @ rhel5 ~] # Cd/usr/local/MySQL [root @ rhel5 MySQL] #. /bin/mysqld_safe -- user = MySQL & // start MySQL, but the startup log cannot be stopped and written under this file:/usr/local/MySQL/data/localhost. err closes the MySQL service [root @ rhel5 MySQL] # mysqladmin-u root-P shutdown // here, the MySQL Root User has not configured a password, so it is null. When you need to enter the password, click the Enter key.
(6) Another simple method for starting MySQL (MySQL has been added to the system service)
[root@ rhel5~]# service mysql.server start [root@ rhel5~]# service mysql.server stop[root@ rhel5~]# service mysql.server restart
If the preceding command appears: mysql. server does not recognize other services
Maybe MySQL has not been added to the system service, and you can add it in another way:
[Root @ rhel5 MySQL] # cp support-files/MySQL. Server/etc/init. d/MySQL // Add the MySQL startup service to the System Service
Note: Copy mysql. server to/etc/init. d and name it MySQL. In some systems, MySQL. server in/usr/local/MySQL/share/MySQL. server, and MySQL in the system. server in/usr/local/MySQL/support-files/MySQL. server.
Then start MySQL with # service MySQL start.
(7) modify the password of the root user of MySQL and enable remote connection.
[Root @ rhel5 ~] # Mysql-u root mysqlmysql> use MySQL; mysql> DESC user; mysql> grant all privileges on *. * To root @ "%" identified by "root"; // Add the remote connection capability to the root user. Mysql> Update user SET Password = PASSWORD ('xxxxxx') where user = 'root'; mysql> select host, user, password from user where user = 'root '; mysql> flush privileges; mysql> exit to log on again: mysql-u root-P if remote connection is not available, disable firewall [root @ rhel5 ~] #/Etc/rc. d/init. d/iptables stop
Note: If the remote connection fails and the MySQL error number 1130 is displayed, add the following statement:
Mysql> grant all privileges on *. * To 'root' @ '% 'identified by' ****** 'with grant option;