Build Linux CentOS6.5 Compile and install mysql5.6
- 2020-06-03 09:06:42
- OfStack
Preparation before installation
Check that mysql is installed on centos with the rpm command, and then uninstall the existing version of mysql
[root@localhost src]# rpm -qa|grep mysql
mysql-libs-5.1.66-2.el6_3.i686
[root@localhost src]# rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.i686
Install mysql through yum to compile the required dependency packages
[root@localhost src]# yum install gcc gcc-c++ perl
Download mysql5. 6 installation package, mysql5. 6 installation package download address: https: / / dev mysql. com get/Downloads/MySQL - 5.6 / mysql - 5.6.36. tar. gz.
Add mysql user groups and users, as well as mysql's installation directory
[root@localhost src]# groupadd mysql
[root@localhost src]# useradd -g mysql -s /sbin/nologin -M mysql
[root@localhost src]# mkdir /usr/local/mysql
[root@localhost src]# id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
Authorize the installation directory for mysql
[root@localhost src]# chown -R mysql.mysql /usr/local/mysql
[root@localhost src]# ll /usr/local
drwxr-xr-x. 2 mysql mysql 4096 May 11 09:09 mysql
Start the installation
mysql 5.6 is configured by cmake. The default cmake can be used to directly enter the configuration. You can also specify the configuration yourself
[root@localhost mysql-5.6.36]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ # Specify installation directory
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \# The specified mysql.sock address
> -DDEFAULT_CHARSET=utf8 \# Specify the default character set
> -DDEFAULT_COLLATION=utf8_general_ci \# Specifies the default collating character set
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \# The installation innodb The storage engine
> -DWITH_MYISAM_STORAGE_ENGINE=1 \ The installation myisam The storage engine
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ The installation archive The storage engine
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ The installation blackhole The storage engine
> -DMYSQL_DATADIR=/usr/local/mysql/data \#mysql Data file storage directory
> -DMYSQL_TCP_PORT=3306 \# port
> -DENABLE_DOWNLOADS=1
After configuration, an error may occur
Error: Could NOT Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
Curses can not be found here, via the yum installation library
[root@localhost src]# yum -y install ncurses-devel
Then delete CMakeCache.txt and redo cmake
[root@localhost mysql-5.6.36]# rm -rf CMakeCache.txt
cmake, make & & make install
Installation data file
After the installation of mysql is completed, the installation file is required. mysql_install_db can be seen in the scripts folder under the installation directory of mysql to install the mysql data file and specify mysql user
[root@localhost mysql]# ls /usr/local/mysql/scripts/
mysql_install_db
[root@localhost mysql]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Start the mysql
[root@localhost mysql]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.. SUCCESS!
Login mysql
[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot
No password is required for the first login. The root login password needs to be set through mysqladmin.
[root@localhost src]# yum install gcc gcc-c++ perl
0
View the mysql configuration file
[root@localhost src]# yum install gcc gcc-c++ perl
1
You can see that the mysql configuration files are stored in multiple locations, in the order they are read
[root@localhost src]# yum install gcc gcc-c++ perl
2
Then copy the ES116en-ES117en.cnf configuration file in the mysql installation directory to /etc/ my.cnf
[root@localhost support-files]# cp my-default.cnf /etc/my.cnf
If there is direct overwrite, it is better to change the owner of /etc/ my.cnf
Environment variables are configured for ease of use
Will start on mysql service/etc/init d/down
[root@localhost src]# yum install gcc gcc-c++ perl
4
Will/usr/local/mysql/bin/directory is added to the environment variables, vim editor vim etc/profile permanent to add environment variables, restart to take effect
[root@localhost src]# yum install gcc gcc-c++ perl
5
If you don't want to reboot, you can also execute the script after editing vim /etc/profile
[root@localhost src]# yum install gcc gcc-c++ perl
6
This method will fail after the terminal is closed