STEP 1. Download
Go to the official download MySQL package .http: //dev.mysql.com
mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
[root@study mysql] pwd /root/mysql [root@study mysql] wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-i686.tar.gz
STEP 2. Unzip
[root@study mysql]pwd /root/mysql [root@study mysql]tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz [root@study mysql]ll drwxr-xr-x. 9 root root 4096 March 19 11:49 mysql-5.7.25-linux-glibc2.12-x86_64
STEP 3. The contents of the directory decompressed move to the designated installation directory, I chose / usr / local / mysql, the establishment of relevant documents and modify file and directory attributes
[root@study mysql]test -d /usr/local/mysql || mkdir /usr/local/mysql All the data in the second step # movement to extract the directory / usr / local / mysql in [root@study mysql] mv mysql-5.7.25-linux-glibc2.12-x86_64/* /usr/local/mysql # See if mysql mysql user names and user group [root@study mysql] cat /etc/passwd | grep mysql [root@study mysql] cat /etc/group | grep mysql # If so, delete users and groups [root@study mysql] userdel -r mysql # Next, create mysql user (system account), mysql user group [root@study mysql] groupadd mysql [root@study mysql] useradd -r -g mysql mysql # Change / users and user groups usr / local / mysql directory [root@study mysql]chown -R mysql:mysql /usr/local/mysql # Set mysql user for non-logged-on user [root@study mysql]usermod -s /sbin/nologin mysql # Set mysql user's home directory is / usr / local / mysql [root@study mysql]usermode -d /usr/local/mysql mysql #### or can be specified directly in the establishment of user time [root@study mysql] useradd -r -s /sbin/nologin -d /usr/local/mysql/ -g mysql # Create the MySQL data directory [root@study mysql]mkdir /var/mysql # Change directory permissions (user and user groups) [root@study mysql]chown -R mysql:mysql /var/mysql # Create a socket file [root@study mysql] touch /tmp/mysqld.sock [root@study mysql] chown mysql:mysql /tmp/mysqld.sock # Create a pid file [root@study mysql] touch /usr/local/mysql/mysqld.pid [root@study mysql] chow mysql:mysql /usr/local/mysql/mysqld.pid
# 创建 日志
[root@study mysql] test -d /var/log/mysql || mkdir /var/log/mysql
[root@study mysql] touch /var/log/mysql/mysqld.log
[root@study mysql] chown -R mysql:mysql /var/log/mysql
STEP 4. Modify Profile /etc/my.cnf
[root@study mysql] vim /etc/my.cnf ### [mysqld] # Data Directory data = / var / mysql # Base directory basedir=/usr/local/mysql # MySQL listening port port=3306 # Soket file socket=/tmp/mysqld.sock # Server Character Set character-set-server = utf8 symbolic-links=0 [mysqld_safe] # Mysql log file log-error=/var/log/mysql/mysqld.log # Mysql pid file pid-file=/usr/local/mysql/mysqld.pid
STEP 5. Installation Initialization
[root@study mysql] /usr/local/mysql/bin/mysqld --intialize --user=mysql --basedir=/usr/local/mysql --datadir=/var/mysql
出现错误
Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive
Try
to copy the source package inside /usr/local/mysql/share/english/errmsg.sys to /usr/share/mysql/errmsg.sys
STEP 6. Start testing and service creation file
[root@study mysql] /usr/local/mysql/bin/mysqld_safe --user=mysql & # If you can pass ps aux | grep mysqld can see the information proved successful start mysql, otherwise look for the corresponding log errors, identify the cause # Creating a Bootable service, can run mysql way daemon [root@sutyd mysql] vim /usr/lib/systemd/system/mysqld.service [Service]
# Type of Service = The forking type
# execution of users and user groups User=mysql MySQL = Group
# PID file PIDFile=/var/run/mysql/mysql.pid
TimeoutSec=0 PermissionsStartOnly=true
#执行字符串
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/mysqld.pid $MYSQLD_OPTS LimitNOFILE = 5000 Restart=on-failure RestartPreventExitStatus=1 PrivateTmp=false [Install] WantedBy=multi-user.target Alias=mysql.service # Corresponding service description can be found in the man systemd.service
STEP 7. Set the boot and open the firewall settings
#boot [root@study mysql] systemctl enable mysqld.service # Firewall [root@study mysql] firewall-cmd --permanent --zone=pulibc --add-port=3306/tcp
[root@study mysql] firewall-cmd --reload