Compile and install MySQL in CentOS 7
Hardware environment: Dell PowerEdge R710
System: CentOS 7*86_64
1) download the mysql-5.1.57 source package (click I download), put in/usr/local/src. Mysql-5.1.57 source code compilation installation steps are as follows.
Since the servers are installed with minimal installation, you need to install the gcc-c ++ and other basic library files. The command is as follows:
[Html] view plaincopy
- Yuminstallgcc
- Yuminstallgcc-c ++
- Yumlist | grepncurses
- Yum-yinstallncurses-devel
- Yuminstallncurses-devel
Generate mysql users and user groups using the following command:
[Html] view plaincopy
- Groupaddmysql
- Useradd-gmysqlmysql
Source code compilation to install the mysql-5.1.57, the command is as follows:
[Html] view plaincopy
- Cd/usr/local/src
- Tarzxvfmysql-5.1.57.tar.gz
- Cdmysql-5.1.57
- ./Configure -- prefix =/usr/local/mysql
- Make & makeinstall & cd ../
2) Configure permissions for mysql and set the data installation path of mysql to/data/mysql. Configure mysql as the service startup status as follows:
[Html] view plaincopy
- Cd/usr/local/mysql
- Cp/usr/local/mysql/share/mysql/my-huge.cnf/etc/my. cnf
- Cp/usr/local/mysql/share/mysql. server/etc/init. d/mysqld
- Chown-Rmysql: mysql/usr/local/mysql/
- Mkdir-p/data/mysql
Here only the system comes with the my-huge.cnf as the MySQL database configuration file, later according to the MySQL status of the operating status for tuning.
3) modify the [mysqld] item of/etc/my. cnf under the MySQL server and add the data storage path for mysql runtime under it, as shown below:
[Html] view plaincopy
- Datadir =/data/mysql
4) run the following command on the server to generate the mysql initialization file and initial database under/data/MySQL:
[Html] view plaincopy
- /Usr/local/mysql/bin/mysql_install_db -- user = mysql -- datadir =/data/mysql
5) Now you can start the MySQL service as a service, as shown below:
[Html] view plaincopy
- Servicemysqldstart
We will configure it as the self-starting status. The command is as follows:
[Html] view plaincopy
- Chkconfigmysqldon
After the configuration is complete, run the following command:
[Html] view plaincopy
- Chkconfig -- listmysqld
The result is as follows, indicating that the above settings are successful:
[Html] view plaincopy
- Mysqld0: off 1: off 2: open 3: Open 4: Open 5: Open 6: Off
6) add mysql environment variables in/usr/bin as follows:
[Html] view plaincopy
- Ln-s/usr/local/mysql/bin/mysql/usr/bin
7) disable the system firewall as follows:
[Html] view plaincopy
- Systemctlstopfirewalld
8) modify the password of the root user and allow remote access, as shown below:
[Html] view plaincopy
- Usemysql;
- Updateusersetpassword = password ("root") whereuser = "root ";
- GRANTALLPRIVILEGESON *. * TO 'root' @ '%' IDENTIFIEDBY 'root' WITHGRANTOPTION;
- Flushprivileges;
At this point, the steps for compiling and installing MySQL under CentOS 7 are complete.