生产环境可用mysql5.7.23安装全过程

生产环境安装5.7.23全过程

先执行initialization.sh优化脚本 详情见 Linux

在安装mysql前,需要先查看一下是否清空了系统自带了mysql
我们这里需要删除系统自带了mysql lib

我们先把mysql放置在/opt下
先上传与线上版本一致的

[[email protected] opt]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[[email protected] opt]# ll
total 629320
-rw-r--r--  1 root root      7214 Mar 27 17:37 initialization.sh
-rw-r--r--  1 root root 644399365 Oct 13  2018 mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 root root      4096 Nov 22  2013 rh
drwxr-xr-x  2 root root      4096 Apr 23 16:34 scripts

第一步:删除过期系统自带的lib

[[email protected] opt]# rpm -qa|grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[[email protected] opt]# find / -name "mysql"
/usr/share/mysql
/usr/lib64/mysql
[[email protected] opt]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
[[email protected] opt]# rpm -qa|grep mysql
[[email protected] opt]# find / -name "mysql"  

第二步创建mysql的用户

[[email protected] opt]# groupadd mysql
[[email protected] opt]# useradd -r -g mysql -s /bin/false mysql

第三步创建mysql的数据目录
[[email protected] opt]# mkdir -p /ivargo/data/mysql

第三步:解压 mysql安装包到/usr/local 下

[[email protected] opt]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
...
...
...

[[email protected] opt]# cd /usr/local/
[[email protected] local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Sep 23  2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23  2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23  2011 games
drwxr-xr-x. 2 root root 4096 Sep 23  2011 include
drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexec
drwxr-xr-x  9 root root 4096 Apr 23 17:12 mysql-5.7.23-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root root 4096 Apr 16  2018 share
drwxr-xr-x. 2 root root 4096 Sep 23  2011 src
到这来有2个方式,方式是  //一个是直接mv 一个是用ln -s 软连接

在这里我们实现和生产上一样的,用mv
第四步:创建/usr/local/mysql
[[email protected] local]# mkdir mysql
[[email protected] local]# ll
total 48
drwxr-xr-x. 2 root root 4096 Sep 23  2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23  2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23  2011 games
drwxr-xr-x. 2 root root 4096 Sep 23  2011 include
drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexec
drwxr-xr-x  2 root root 4096 Apr 23 17:20 mysql
drwxr-xr-x  9 root root 4096 Apr 23 17:12 mysql-5.7.23-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root root 4096 Apr 16  2018 share
drwxr-xr-x. 2 root root 4096 Sep 23  2011 src
[[email protected] local]# mv /usr/local/mysql-5.7.23-linux-glibc2.12-x86_64/* /usr/local/mysql
[[email protected] local]# rm -rf mysql-5.7.23-linux-glibc2.12-x86_64/
[[email protected] local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Sep 23  2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23  2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23  2011 games
drwxr-xr-x. 2 root root 4096 Sep 23  2011 include
drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexec
drwxr-xr-x  9 root root 4096 Apr 23 17:21 mysql
drwxr-xr-x. 2 root root 4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root root 4096 Apr 16  2018 share
drwxr-xr-x. 2 root root 4096 Sep 23  2011 src
第五步:设置/usr/local/mysql 的权限
[[email protected] local]# pwd
/usr/local
[[email protected] local]# chown -R mysql:mysql mysql
第六步:修改mysql 配置文件
[[email protected] local]# pwd
/usr/local
[[email protected] local]# ll
total 44
drwxr-xr-x. 2 root  root  4096 Sep 23  2011 bin
drwxr-xr-x. 2 root  root  4096 Sep 23  2011 etc
drwxr-xr-x. 2 root  root  4096 Sep 23  2011 games
drwxr-xr-x. 2 root  root  4096 Sep 23  2011 include
drwxr-xr-x. 2 root  root  4096 Sep 23  2011 lib
drwxr-xr-x. 2 root  root  4096 Sep 23  2011 lib64
drwxr-xr-x. 2 root  root  4096 Sep 23  2011 libexec
drwxr-xr-x  9 mysql mysql 4096 Apr 23 17:21 mysql
drwxr-xr-x. 2 root  root  4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root  root  4096 Apr 16  2018 share
drwxr-xr-x. 2 root  root  4096 Sep 23  2011 src
[[email protected] local]# cd mysql/
[root[email protected] mysql]# ll
total 52
drwxr-xr-x  2 mysql mysql  4096 Apr 23 17:12 bin
-rw-r--r--  1 mysql mysql 17987 Jun  8  2018 COPYING
drwxr-xr-x  2 mysql mysql  4096 Apr 23 17:13 docs
drwxr-xr-x  3 mysql mysql  4096 Apr 23 17:11 include
drwxr-xr-x  5 mysql mysql  4096 Apr 23 17:12 lib
drwxr-xr-x  4 mysql mysql  4096 Apr 23 17:12 man
-rw-r--r--  1 mysql mysql  2478 Jun  8  2018 README
drwxr-xr-x 28 mysql mysql  4096 Apr 23 17:12 share
drwxr-xr-x  2 mysql mysql  4096 Apr 23 17:12 support-files
[[email protected] mysql]# cd support-files/
[[email protected] support-files]# ll
total 24
-rw-r--r-- 1 mysql mysql   773 Jun  8  2018 magic
-rwxr-xr-x 1 mysql mysql  1061 Jun  8  2018 mysqld_multi.server
-rwxr-xr-x 1 mysql mysql   894 Jun  8  2018 mysql-log-rotate
-rwxr-xr-x 1 mysql mysql 10576 Jun  8  2018 mysql.server
[[email protected] support-files]# cp mysql.server /etc/init.d/mysql
然后修改/etc/init.d/mysql的参数,
vim /etc/init.d/mysql
修改
basedir=/usr/local/mysql
datadir=/ivargo/data/mysql

设置mysql启动的配置文件my.cnf  设置配置文件/etc/my.cnf
[[email protected] support-files]# find / -name "my.cnf"
[[email protected] opt]# mv my.cnf /etc/
[[email protected] opt]# ls -l /etc/my.cnf
-rw-r--r-- 1 root root 1649 Oct 11  2018 /etc/my.cnf
第七步:初始化mysql
[[email protected] bin]# pwd
/usr/local/mysql/bin
初始化命令
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/ivargo/data/mysql
[[email protected] bin]# ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/ivargo/data/mysql
...
...
...
第八步 :启动mysql 并设置 开机自启动 chkconfig mysql on
[[email protected] bin]# service mysql start
Starting MySQL.. SUCCESS!
[[email protected] bin]# netstat -lntup
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      1531/sshd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1607/master
tcp        0      0 :::22                       :::*                        LISTEN      1531/sshd
tcp        0      0 ::1:25                      :::*                        LISTEN      1607/master
tcp        0      0 :::3306                     :::*                        LISTEN      4567/mysqld    

第九步 :重新设置mysql密码

[[email protected] bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23-log

Copyright (c) 2000, 2018, 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.

@(none)> SET PASSWORD FOR ‘root‘@‘localhost‘=PASSWORD(‘xxx‘);
Query OK, 0 rows affected, 1 warning (0.01 sec)
@(none)> flush privileges;
Query OK, 0 rows affected (0.00 sec)

第十步:设置mysql的环境变量
我这里用的 自己的方法

echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ >> /etc/profile
tail -1 /etc/profile
source /etc/profile
[[email protected] opt]# which mysql
/usr/local/mysql/bin/mysql

第十一步:优化mysql

@(none)> select user,host from mysql.user;  //没有优化前
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

[[email protected] opt]# find / -name "mysql_secure_installation"
/usr/local/mysql/bin/mysql_secure_installation

执行初始化命令之后,
@(none)> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

@(none)> select user,host from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

需要给生产上root % 权限

GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘XXX‘ WITH GRANT OPTION;
@(none)> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘XXX‘ WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)

@(none)> flush privileges;
Query OK, 0 rows affected (0.00 sec)

@(none)> select user,host from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)

原文地址:https://blog.51cto.com/12445535/2385095

时间: 2024-10-09 12:07:41

生产环境可用mysql5.7.23安装全过程的相关文章

生产环境可用redis4.0.11安装全过程

生产环境可用redis4.0.11安装全过程操作系统版本为 centos6.5 先执行initialization.sh优化脚本 详情见 初始化脚本我们线上用的是redis-4.0.11.tar.gz根据日志内容进行优化 //后面会提现处理,我们这里可以先执行,不明白的同学,可以继续往后看. 优化1: [[email protected] conf]# echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf [[email p

在Ubuntu 14.04上设置生产环境可用的Node.js

在Ubuntu 14.04上设置生产环境可用的Node.js 提供:ZStack社区 前言 Node.js是一个开源的JavaScript运行时环境,开发者可以用它方便的构建服务器端应用和网络应用.Node.js可在Linux.OS X.FreeBSD和Windows上运行,在其上运行的应用使用JavaScript编写.Node.js应用可以在命令行运行,然而本文的目的在于以服务的方式运行Node.js应用,让这些应用可以在系统重启或遇到错误时自动重启,以配合生产环境的需求. 本文将设置一个可用

构建生产环境可用的高可用kubernetes集群

kubernetes集群三步安装 构建生产环境可用的高可用kubernetes集群 | sealos项目地址 特性 [x] 支持任意节点的etcd集群自动构建,且etcd集群使用安全证书,通过static pod方式启动,这样可以通过监控pod来监控etcd集群健康状态 [x] 支持多master节点,允许任意一台master宕机集群功能不受影响 [x] calico使用etcd集群,配置安全证书,网络管控数据无单点故障 [x] 包含dashboard, heapster coreDNS add

Linux运维一:生产环境CentOS6.6系统的安装

CentOS 6.6 x86_64官方正式版系统(64位)下载地址 系统之家:http://www.xitongzhijia.net/linux/201412/33603.html 百度网盘:http://pan.baidu.com/s/1i5HSsnz 本博客大部分文章如无特别说明都是基于该系统之上的! Linux系统磁盘分区知识简介 1)磁盘在使用前一般要先分区 2)磁盘分区有主分区,扩展分区和逻辑分区之分.一块磁盘最多可以有4个主分区,其中一个主分区的位置可以用一个扩展分区替换,在这个扩展

生产环境下:LAMP源码安装,搭建zabbix监控

1.系统环境检查,版本说明 1)版本说明 #httpd-2.4.25#mysql-5.7.17-linux-glibc2.5-x86_64 二进制压缩版#php5.6.30 #zabbix-3.0.8 2)关闭selinux.iptables,检查系统版本信息 sed -i 's/SELINUX=enabled/SELINUX=disabled/g' /etc/selinux/configgetenforce 0/etc/init.d/iptables stopcat /etc/redhat-r

生产环境实践Mysql5.7主从+Atlas实现读写分离

Mysql主从搭建 主从复制可以使MySQL数据库主服务器的主数据库,复制到一个或多个MySQL从服务器从数据库,默认情况下,复制异步; 根据配置,可以复制数据库中的所有数据库,选定的数据库或甚至选定的表.MySQL的工作方式是单进程多线程的方式,那么线程的多寡则会极大的影响到MySQL的效率,而在早期MySQL的主从都是由单线程进行的,使得主从复制除了相关的客观因素外还受到自身的影响:为此在MySQL的5.7版本中对多线程主从复制来进一步的改善,在MySQL 5.7中是按照逻辑时钟(类似CPU

centos7.2 环境下 mysql-5.1.73 安装配置

安装mysql,安装前准备 如果mysql用户不存在,那么添加mysql用户 groupadd mysql useradd -g mysql mysql mysql编译安装 tar -zxvf mysql-5.1.73.tar.gz cd mysql-5.1.73 yum install ncurses ncurses-devel ./configure '--prefix=/usr/local/mysql' '--without-debug' '--with-charset=utf8' '--

mysql5.6.23安装 步骤

1. 准备好配置文件 my.cnf 2.建立my.cnf中用到的必要的目录 3.在mysql目录下有个scripts/mysql_install_db, 执行: scripts/mysql_install_db --defaults-file=/opt/etc/my.cnf --user=mysql 4.启动服务 /opt/mysql/bin/mysqld_safe --defaults-file=/opt/io_nvme/mysql_thresholds/etc/my.cnf & 5. 修改密

Ubuntu18.04编译安装mysql5.7.23

本博客为源码安装mysql5.7.23案例全过程 环境ubuntu18.04 安装规划: 配置文件:/etc/my.cnf 数据目录:/r2/mysqldata 安装目录:/usr/local/mysql 1.下载mysql-boost wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.23.tar.gz 2.安装工具 sudo apt-get install cmake -y apt-get install gcc