重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
生产环境安装5.7.23全过程
成都创新互联公司是专业的延庆网站建设公司,延庆接单;提供网站建设、成都网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行延庆网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
先执行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]# 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
[root@prd3-mysql-0-36 opt]# rpm -qa|grep mysql
mysql-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]# 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
[root@prd3-mysql-0-36 local]# mkdir mysql
[root@prd3-mysql-0-36 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
[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]# 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 的权限
[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]# 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
[root@prd3-mysql-0-36 local]# cd mysql/
[root@prd3-mysql-0-36 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
[root@prd3-mysql-0-36 mysql]# cd support-files/
[root@prd3-mysql-0-36 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
[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/mysql
datadir=/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 start
Starting MySQL.. SUCCESS!
[root@prd3-mysql-0-36 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密码
[root@prd3-mysql-0-36 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
[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)