CentOS 6.6 Source code compilation and installation MySQL 5.7. 18 tutorial details

  • 2021-08-21 21:40:47
  • OfStack

1. Add users and groups

1. Add an mysql user group


# groupadd mysql

2. Add an mysql user


# useradd -g mysql -s /bin/nologin mysql -M 

2. Check whether mysql is installed in the system. If installation requires uninstallation,


# rpm -qa | grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
# rpm -e mysql-libs-5.1.73-3.el6_5.x86_64 --nodeps

3. Install required dependency packages


# yum -y install wget gcc-c++ ncurses-devel cmake 

Step 4 Install

1. Download the latest version of MySQL

Enter http://dev.mysql.com/downloads/mysql/ and select Generic Linux under Source Code. Select the mysql download with the boost library. MySQL5.7 has requirements for boost library, and those with boost library will avoid some pits.

# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz

2. Unzip and install


# tar xf mysql-boost-5.7.18.tar.gz
# cd mysql-5.7.18
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=boost/boost_1_59_0
# make && make install

MySQL will be installed into the/usr/local/mysql directory.

3. Enter the installation directory and create the data directory


# cd /usr/local/mysql
# mkdir data

4. Modify the/usr/local/mysql directory permissions


# chown -R mysql. /usr/local/mysql 

5. Initialize the database


# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

Note:

1. The previous version mysql_install_db was under mysql_basedir/script, 5.7 was placed in the mysql_install_db/bin directory and has been discarded
2. "--initialize" generates a random password (~ /.mysql_secret) and "--initialize-insecure" does not generate a password
3.--No data files in the datadir destination directory
4. After using the--initialize parameter, 1 must remember the generated password, otherwise you cannot log in to the database.

6. Copy the startup file to/etc/init. d/and reset to mysqld


# /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

7. Create a configuration file

After installation, no my. cnf configuration file was found, so manually create a


# vim /etc/my.cnf
[mysqld]
basedir =/usr/local/mysql
datadir =/usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
[client]
socket=/tmp/mysql.sock 

8. Start mysql


# useradd -g mysql -s /bin/nologin mysql -M 
0

9. Log in to mysql


# useradd -g mysql -s /bin/nologin mysql -M 
1

10. Modify the root password


# useradd -g mysql -s /bin/nologin mysql -M 
2

11. Log out and log in again


# /usr/local/mysql/bin/mysql -uroot -p 'New password '

Related articles: