1. Download MySQL 5.6.36 compile free installation package and upload it to / usr/local/src directory (you can also use wget command to download it directly to this directory)
Download address https://yunpan.360.cn/surl_ymCGfFYt2Ya
2. Decompression
[root@JSH-01 src]# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
3. Move the extracted file to / usr/local / and rename it mysql
[root@JSH-01 src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql [root@JSH-01 local]# ls aegis bin etc games include lib lib64 libexec mysql sbin share src
IV. enter mysql directory
[root@JSH-01 local]# cd mysql [root@JSH-01 mysql]# ls bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
V. create mysql user and SQL database storage directory
[root@JSH-01 mysql]# useradd mysql [root@JSH-01 mysql]# mkdir /data
6. Initialize the installation of MySQL and make the user and directory, and install the related dependency package before installation.
[root@JSH-01 mysql]# yum install -y perl gcc kernel-devel [root@JSH-01 mysql]# yum install -y autoconf [root@JSH-01 mysql]# yum install -y libaio [root@JSH-01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql After execution, enter the command echo $? Enter to see whether the output is 0 or 1. If it is 0, the installation is successful. Or if you see OK twice, it means the installation is successful. [root@JSH-01 mysql]# echo $? 0
VII. Copy configuration file and startup script
[root@JSH-01 mysql]# CP support files / my-default.cnf / etc / my.cnf cp: overwrite '/etc/my.cnf'? y [root@JSH-01 mysql]# CP support files / mysql.server / etc / init.d/mysqld (copy the startup script and rename it mysqld) [root@JSH-01 mysql]# vi /etc/init.d/mysqld //After copying, edit the startup script mysqld and define basedir and datadir basedir=/usr/local/mysql datadir=/data/mysql
VIII. After the script is saved and started, change its permission to 755 (the actual default permission of this file is 755)
[root@JSH-01 mysql]# ls -l /etc/init.d/mysqld view file details -rwxr-xr-x 1 root root 10592 Nov 25 20:08 /etc/init.d/mysqld
IX. setting MySQL startup
[root@JSH-01 mysql]# chkconfig --add mysqld [root@JSH-01 mysql]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
X. start MySQL service
[root@JSH-01 mysql]# service mysqld start Starting MySQL.Logging to '/data/mysql/JSH-01.err'. [ OK ] [root@JSH-01 mysql]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3234/sshd tcp6 0 0 :::3306 :::* LISTEN 22293/mysqld //It can be seen that the service port used by MySQL is 3306
Xi. How to stop MySQL service
You can use the command kill mysqld or service mysqld stop
12. How to log in to MySQL after installation?
[root@JSH-01 ~]# mysql -uroot -bash: mysql: Command not found //The prompt is not found because the mysql command path is: / usr/local/mysql/bin / the environment variable needs to be changed at this time. Edit the configuration file VI / etc / profile to write export PATH=$PATH:/usr/local/mysql/bin / to the last line. [root@JSH-01 ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@JSH-01 ~]# export PATH=$PATH:/usr/local/mysql/bin/ [root@JSH-01 ~]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.36 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> quit; Bye [root@JSH-01 bin]# vi /etc/profile [root@JSH-01 bin]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.36 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>