千家信息网

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

发表于:2024-12-12 作者:千家信息网编辑
千家信息网最后更新 2024年12月12日,生产环境安装5.7.23全过程先执行initialization.sh优化脚本 详情见 Linux在安装mysql前,需要先查看一下是否清空了系统自带了mysql我们这里需要删除系统自带了mysql
千家信息网最后更新 2024年12月12日生产环境可用mysql5.7.23安装全过程

生产环境安装5.7.23全过程

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

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

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

[root@prd3-mysql01-180 opt]# cat /etc/redhat-release CentOS release 6.5 (Final)
[root@prd3-mysql-0-36 opt]# lltotal 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.gzdrwxr-xr-x. 2 root root      4096 Nov 22  2013 rhdrwxr-xr-x  2 root root      4096 Apr 23 16:34 scripts

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

[root@prd3-mysql-0-36 opt]# rpm -qa|grep mysqlmysql-libs-5.1.71-1.el6.x86_64[root@prd3-mysql-0-36 opt]# find / -name "mysql"/usr/share/mysql/usr/lib64/mysql[root@prd3-mysql-0-36 opt]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64[root@prd3-mysql-0-36 opt]# rpm -qa|grep mysql                            [root@prd3-mysql-0-36 opt]# find / -name "mysql"  
补充安装相关的依赖  //要做,防止后面出错[root@ct6 ~]# yum -y install perl-Module-Install.noarch[root@ct6 ~]# rpm -qa|grep 'perl-Module-Install'       perl-Module-Install-0.91-4.el6.noarch

第二步创建mysql的用户

[root@prd3-mysql-0-36 opt]# groupadd mysql[root@prd3-mysql-0-36 opt]# useradd -r -g mysql -s /bin/false mysql

第三步创建mysql的数据目录
[root@prd3-mysql-0-36 opt]# mkdir -p /ivargo/data/mysql

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

[root@prd3-mysql-0-36 opt]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/.........[root@prd3-mysql-0-36 opt]# cd /usr/local/[root@prd3-mysql-0-36 local]# lltotal 44drwxr-xr-x. 2 root root 4096 Sep 23  2011 bindrwxr-xr-x. 2 root root 4096 Sep 23  2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23  2011 gamesdrwxr-xr-x. 2 root root 4096 Sep 23  2011 includedrwxr-xr-x. 2 root root 4096 Sep 23  2011 libdrwxr-xr-x. 2 root root 4096 Sep 23  2011 lib64drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexecdrwxr-xr-x  9 root root 4096 Apr 23 17:12 mysql-5.7.23-linux-glibc2.12-x86_64drwxr-xr-x. 2 root root 4096 Sep 23  2011 sbindrwxr-xr-x. 5 root root 4096 Apr 16  2018 sharedrwxr-xr-x. 2 root root 4096 Sep 23  2011 src到这来有2个方式,方式是  //一个是直接mv 一个是用ln -s 软连接在这里我们实现和生产上一样的,用mv
第四步:创建/usr/local/mysql[root@prd3-mysql-0-36 local]# mkdir mysql[root@prd3-mysql-0-36 local]# lltotal 48drwxr-xr-x. 2 root root 4096 Sep 23  2011 bindrwxr-xr-x. 2 root root 4096 Sep 23  2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23  2011 gamesdrwxr-xr-x. 2 root root 4096 Sep 23  2011 includedrwxr-xr-x. 2 root root 4096 Sep 23  2011 libdrwxr-xr-x. 2 root root 4096 Sep 23  2011 lib64drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexecdrwxr-xr-x  2 root root 4096 Apr 23 17:20 mysqldrwxr-xr-x  9 root root 4096 Apr 23 17:12 mysql-5.7.23-linux-glibc2.12-x86_64drwxr-xr-x. 2 root root 4096 Sep 23  2011 sbindrwxr-xr-x. 5 root root 4096 Apr 16  2018 sharedrwxr-xr-x. 2 root root 4096 Sep 23  2011 src[root@prd3-mysql-0-36 local]# mv /usr/local/mysql-5.7.23-linux-glibc2.12-x86_64/* /usr/local/mysql[root@prd3-mysql-0-36 local]# rm -rf mysql-5.7.23-linux-glibc2.12-x86_64/[root@prd3-mysql-0-36 local]# lltotal 44drwxr-xr-x. 2 root root 4096 Sep 23  2011 bindrwxr-xr-x. 2 root root 4096 Sep 23  2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23  2011 gamesdrwxr-xr-x. 2 root root 4096 Sep 23  2011 includedrwxr-xr-x. 2 root root 4096 Sep 23  2011 libdrwxr-xr-x. 2 root root 4096 Sep 23  2011 lib64drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexecdrwxr-xr-x  9 root root 4096 Apr 23 17:21 mysqldrwxr-xr-x. 2 root root 4096 Sep 23  2011 sbindrwxr-xr-x. 5 root root 4096 Apr 16  2018 sharedrwxr-xr-x. 2 root root 4096 Sep 23  2011 src
第五步:设置/usr/local/mysql 的权限[root@prd3-mysql-0-36 local]# pwd/usr/local[root@prd3-mysql-0-36 local]# chown -R mysql:mysql mysql
第六步:修改mysql 配置文件[root@prd3-mysql-0-36 local]# pwd/usr/local[root@prd3-mysql-0-36 local]# lltotal 44drwxr-xr-x. 2 root  root  4096 Sep 23  2011 bindrwxr-xr-x. 2 root  root  4096 Sep 23  2011 etcdrwxr-xr-x. 2 root  root  4096 Sep 23  2011 gamesdrwxr-xr-x. 2 root  root  4096 Sep 23  2011 includedrwxr-xr-x. 2 root  root  4096 Sep 23  2011 libdrwxr-xr-x. 2 root  root  4096 Sep 23  2011 lib64drwxr-xr-x. 2 root  root  4096 Sep 23  2011 libexecdrwxr-xr-x  9 mysql mysql 4096 Apr 23 17:21 mysqldrwxr-xr-x. 2 root  root  4096 Sep 23  2011 sbindrwxr-xr-x. 5 root  root  4096 Apr 16  2018 sharedrwxr-xr-x. 2 root  root  4096 Sep 23  2011 src[root@prd3-mysql-0-36 local]# cd mysql/[root@prd3-mysql-0-36 mysql]# lltotal 52drwxr-xr-x  2 mysql mysql  4096 Apr 23 17:12 bin-rw-r--r--  1 mysql mysql 17987 Jun  8  2018 COPYINGdrwxr-xr-x  2 mysql mysql  4096 Apr 23 17:13 docsdrwxr-xr-x  3 mysql mysql  4096 Apr 23 17:11 includedrwxr-xr-x  5 mysql mysql  4096 Apr 23 17:12 libdrwxr-xr-x  4 mysql mysql  4096 Apr 23 17:12 man-rw-r--r--  1 mysql mysql  2478 Jun  8  2018 READMEdrwxr-xr-x 28 mysql mysql  4096 Apr 23 17:12 sharedrwxr-xr-x  2 mysql mysql  4096 Apr 23 17:12 support-files[root@prd3-mysql-0-36 mysql]# cd support-files/[root@prd3-mysql-0-36 support-files]# lltotal 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[root@prd3-mysql-0-36 support-files]# cp mysql.server /etc/init.d/mysql然后修改/etc/init.d/mysql的参数,vim /etc/init.d/mysql修改basedir=/usr/local/mysqldatadir=/ivargo/data/mysql设置mysql启动的配置文件my.cnf  设置配置文件/etc/my.cnf[root@prd3-mysql-0-36 support-files]# find / -name "my.cnf"[root@prd3-mysql-0-36 opt]# mv my.cnf /etc/[root@prd3-mysql-0-36 opt]# ls -l /etc/my.cnf -rw-r--r-- 1 root root 1649 Oct 11  2018 /etc/my.cnf
第七步:初始化mysql[root@prd3-mysql-0-36 bin]# pwd/usr/local/mysql/bin初始化命令./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/ivargo/data/mysql[root@prd3-mysql-0-36 bin]# ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/ivargo/data/mysql.........
第八步 :启动mysql 并设置 开机自启动 chkconfig mysql on[root@prd3-mysql-0-36 bin]# service mysql startStarting MySQL.. SUCCESS! [root@prd3-mysql-0-36 bin]# netstat -lntupActive 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密码

[root@prd3-mysql-0-36 bin]# ./mysql -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.23-logCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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/profiletail -1 /etc/profilesource /etc/profile[root@prd3-mysql-0-36 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)[root@prd3-mysql-0-36 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)
0