Compile and install MySQL 5.6.14 in CentOS 6.4
MySQL 6.4 installed through yum in CentOS 5.1 is old, so I want to install the later version 5.6.14 through the source code.
Body: 1: uninstall the old version
Run the following command to check whether MySQL Server is installed.
rpm -qa | grep mysql
If yes, run the following command to uninstall it:
Rpm-e mysql // normal deletion mode rpm-e -- nodeps mysql // strong deletion mode. If you use the preceding command to delete a file, the system prompts other dependent files, you can use this command to forcibly delete it.
Ii. Install the packages required for installing and compiling MySQL code
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
Download MySQL 5.6.14
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.14.tar.gztar xvf mysql-5.6.14.tar.gzcd mysql-5.6.14
Compile and install
cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/usr/local/mysql/data \-DSYSCONFDIR=/etc \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_cimake && make install
For compilation parameters, see http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html.
The entire process takes about 30 minutes ...... Long wait
Iii. Configure MySQL to set permissions
Run the following command to check whether mysql users and user groups exist:
Cat/etc/passwd view User List cat/etc/group view User group list
Create if no
groupadd mysqluseradd -g mysql mysql
Modify/usr/local/mysql Permissions
chown -R mysql:mysql /usr/local/mysql
Modify/usr/local/mysql Permissions
Initialize Configuration
Enter the installation path
cd /usr/local/mysql
Go to the installation path, execute the initialization configuration script, and create the database and table that comes with the system.
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
Note: when starting the MySQL service, I will be searched in certain order. cnf, which is first found in the/etc directory. If no cnf is found, "$ basedir/my. cnf ", in this example/usr/local/mysql/my. cnf, which is the default location of the new MySQL configuration file!
Note: After the minimal installation of the CentOS 6.4 operating system is completed, a my. cnf, You need to rename this file to another name, such as:/etc/my. cnf. bak. Otherwise, the file will interfere with the correct configuration of MySQL installed by source code, resulting in startup failure.
After updating the system using "yum update", you need to check whether there will be an extra my. cnf in The/etc directory. If there are more, rename it to something else. Otherwise, MySQL will use this configuration file to start, which may cause problems such as failure to start normally.
Start MySQL
Add a service, copy the service script to the init. d directory, and set startup
Cp support-files/mysql. server/etc/init. d/mysqlchkconfig mysql onservice mysql start -- start MySQL
Configure the user
After MySQL is started successfully, the root user has no password by default. We need to set the root password.
Before setting, we need to set the PATH first, or we cannot directly call mysql
Modify the/etc/profile file and add
PATH=/usr/local/mysql/bin:$PATHexport PATH
Close the file and run the following command to make the configuration take effect immediately
source /etc/profile
Now, we can directly enter mysql in the terminal to enter the mysql environment.
Run the following command to change the root password:
mysql -uroot mysql> SET PASSWORD = PASSWORD('123456');
To set remote access for the root user, run
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
When the red password is used for remote access, the root user password may be different from the local password.
Configure Firewall
Port 3306 of the firewall is disabled by default. To access the firewall remotely, you must enable this port.
Open/etc/sysconfig/iptables
In "-a input-m state -- state NEW-m tcp-p-dport 22-j ACCEPT", add:
-A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT
Save and close the file. Run the following command in the terminal to refresh the Firewall Configuration:
service iptables restart
OK. All configurations are complete. You can access your MySQL instance ~
Bytes ------------------------------------------------------------------------------------------------------------------
In CentOS 7, Firewalld is used as the firewall by default. Therefore, after iptables is modified, it does not work after the system is restarted.
The method for adding a port to Firewalld is as follows:
Firewall-cmd -- zone = public -- add-port = 3306/tcp -- permanent
Firewall-cmd -- reload