环境准备

版本 IP 配置 主机名
Centos7.2-1511 19.168.100. 2G 2vcpu 40G硬盘 Server

上传MySQL二进制免编译包

  1. # 上传文件包
  2. [root@localhost ~]# ls
  3. anaconda-ks.cfg mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
  4. # 修改主机名
  5. [root@localhost ~]# hostnamectl set-hostname server
  6. [root@localhost ~]# su
  7. # 关闭防火墙
  8. [root@serve ~]# systemctl stop firewalld
  9. # 关闭selinux
  10. [root@serve ~]# setenforce 0

安装MySQL

  1. # 准备安装包
  2. [root@server ~]# ll -h mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
  3. -rw-r--r-- 1 root root 385M Sep 11 22:34 mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
  4. # 解压
  5. [root@server ~]# tar -zxf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
  6. # 移动到指定目录
  7. [root@server ~]# mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql
  8. # 创建MySQL启动用户,不可登录
  9. [root@server ~]# useradd -s /sbin/nologin mysql
  10. # 创建存放数据目录
  11. [root@server ~]# mkdir -p /data/mysql
  12. # 更改所属组,所属用户权限
  13. [root@server ~]# chown -R mysql:mysql /data/mysql/
  14. [root@server ~]# ls -la /data/mysql/
  15. total 0
  16. drwxr-xr-x 2 mysql mysql 6 Sep 11 22:37 .
  17. drwxr-xr-x 3 root root 18 Sep 11 22:37 ..
  18. [root@server ~]# cd /usr/local/mysql/
  19. # 安装依赖
  20. [root@server ~]# yum install -y perl-Module-Install
  21. [root@server mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
  22. [root@server mysql]# cp support-files/my-default.cnf /etc/my.cnf
  23. cp: overwrite ‘/etc/my.cnf’? y
  24. # 修改MySQL的my.cnf文件
  25. [root@server mysql]# vim /etc/my.cnf
  26. basedir = /usr/local/mysql
  27. datadir = /data/mysql
  28. port = 3306
  29. server_id = 29
  30. socket = /tmp/mysql.sock
  31. # 配置启动脚本
  32. [root@server mysql]# cp support-files/mysql.server /etc/init.d/mysqld
  33. [root@server mysql]# chmod 777 /etc/init.d/mysqld
  34. [root@server mysql]# vim /etc/init.d/mysqld
  35. basedir=/usr/local/mysql
  36. datadir=/data/mysql
  37. [root@server mysql]# chkconfig --add mysqld
  38. [root@server mysql]# chkconfig mysql on
  39. [root@server mysql]# service mysqld start
  40. Starting MySQL. SUCCESS!
  41. [root@server mysql]# netstat -ntlp
  42. Active Internet connections (only servers)
  43. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  44. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1462/sshd
  45. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2605/master
  46. tcp6 0 0 :::3306 :::* LISTEN 7891/mysqld
  47. tcp6 0 0 :::22 :::* LISTEN 1462/sshd
  48. tcp6 0 0 ::1:25 :::* LISTEN 2605/master
  49. # 配置环境变量
  50. [root@server mysql]# vim /etc/profile
  51. # 最后一行添加
  52. PATH=$PATH:/usr/lcoal/mysql/bin
  53. [root@server mysql]# source /etc/profile
  54. [root@server mysql]# mysqladmin -uroot password '000000'
  55. Warning: Using a password on the command line interface can be insecure.
  56. [root@server mysql]# mysql -uroot -p000000
  57. Warning: Using a password on the command line interface can be insecure.
  58. Welcome to the MySQL monitor. Commands end with ; or \g.
  59. Your MySQL connection id is 2
  60. Server version: 5.6.47 MySQL Community Server (GPL)
  61. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
  62. Oracle is a registered trademark of Oracle Corporation and/or its
  63. affiliates. Other names may be trademarks of their respective
  64. owners.
  65. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  66. mysql> Ctrl-C -- exit!
  67. Aborted
  68. [root@server mysql]#

完成安装