Binary installation of MySQL under centos7

The database installation mainly has the following installation methods:

1. The characteristics of rpm and yum installation methods: the installation speed is fast, but many things cannot be modified, such as paths and functions cannot be customized 2.
Compilation and installation: slow installation, but many things can be modified, such as paths and function customization
3. Binary installation: install fast and can customize something

Let's talk about the binary installation of MySQL:

1. Download: Enter MySQL official website www.mysql.com , click download.
Please add a picture description
2. Download MySQL Community Edition.
Please add a picture description
3. Select MySQL Community Server.
Please add a picture description
4. As shown in the figure, select the mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz version, see clearly that the compressed package ends with .tar, gz, click to download, this is the binary version.
Please add a picture description
5. Select Direct Install.
Please add a picture description
6. Enter the configured virtual machine, log in, and enter ip add to obtain the IP address.
If there is no configuration, you can refer to my VMware17 nanny-level tutorial for creating a new configuration virtual machine . Please add a picture description
7. Enter Xshell, if not, you can go to Xshell official website to download, it is recommended to download xftp at the same time. These two software are good helpers for school Linux.
Set a name, enter the IP address you just obtained, and click Connect.
Please add a picture description
8. Click xftp, and drag the downloaded binary file to the right.
Please add a picture description
If you have not downloaded xftp, you can use the lrzsz that comes with Linux.
lrzsz is used to transfer files between Linux and windows systems, first download lrzsz:

[root@localhost ~]# yum install lrzsz -y

Use the rz command to call up a window to select the Windows file to import to Linux, as shown in the figure:

[root@localhost ~]# rz

Please add a picture description

9. Run the following script for one-click installation.
(1) Create a new script:

vim   onekey_install_mysql_binary_v3.sh

(2) Copy the following code to the script:
login password: **Sanchuan123#** The password can be changed in the corresponding line of the script

#!/bin/bash

#解决软件的依赖关系
yum  install cmake ncurses-devel gcc  gcc-c++  vim  lsof bzip2 openssl-devel ncurses-compat-libs -y

#解压mysql二进制安装包
tar  xf  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

#移动mysql解压后的文件到/usr/local下改名叫mysql
mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql

#新建组和用户 mysql
groupadd mysql
#mysql这个用户的shell 是/bin/false 属于mysql组 
useradd -r -g mysql -s /bin/false mysql

#关闭firewalld防火墙服务,并且设置开机不要启动
service firewalld stop
systemctl  disable  firewalld

#临时关闭selinux
setenforce 0
#永久关闭selinux
sed -i '/^SELINUX=/ s/enforcing/disabled/'  /etc/selinux/config

#新建存放数据的目录
mkdir  /data/mysql -p
#修改/data/mysql目录的权限归mysql用户和mysql组所有,这样mysql用户可以对这个文件夹进行读写了
chown mysql:mysql /data/mysql/
#只是允许mysql这个用户和mysql组可以访问,其他人都不能访问
chmod 750 /data/mysql/

#进入/usr/local/mysql/bin目录
cd /usr/local/mysql/bin/

#初始化mysql
./mysqld  --initialize --user=mysql --basedir=/usr/local/mysql/  --datadir=/data/mysql  &>passwd.txt

#让mysql支持ssl方式登录的设置
./mysql_ssl_rsa_setup --datadir=/data/mysql/

#获得临时密码
tem_passwd=$(cat passwd.txt |grep "temporary"|awk '{print $NF}')
  #$NF表示最后一个字段
  # abc=$(命令)  优先执行命令,然后将结果赋值给abc 

# 修改PATH变量,加入mysql bin目录的路径
#临时修改PATH变量的值
export PATH=/usr/local/mysql/bin/:$PATH
#重新启动linux系统后也生效,永久修改
echo  'PATH=/usr/local/mysql/bin:$PATH' >>/root/.bashrc

#复制support-files里的mysql.server文件到/etc/init.d/目录下叫mysqld
cp  ../support-files/mysql.server   /etc/init.d/mysqld

#修改/etc/init.d/mysqld脚本文件里的datadir目录的值
sed  -i '70c  datadir=/data/mysql'  /etc/init.d/mysqld

#生成/etc/my.cnf配置文件
cat  >/etc/my.cnf  <<EOF
[mysqld_safe]

[client]
socket=/data/mysql/mysql.sock

[mysqld]
socket=/data/mysql/mysql.sock
port = 3306
open_files_limit = 8192
innodb_buffer_pool_size = 512M
character-set-server=utf8

[mysql]
auto-rehash
prompt=\\u@\\d \\R:\\m  mysql>
EOF

#修改内核的open file的数量
ulimit -n 1000000
#设置开机启动的时候也配置生效
echo "ulimit -n 1000000" >>/etc/rc.local
chmod +x /etc/rc.d/rc.local


#启动mysqld进程
service mysqld start

#将mysqld添加到linux系统里服务管理名单里
/sbin/chkconfig --add mysqld
#设置mysqld服务开机启动
/sbin/chkconfig mysqld on

#初次修改密码需要使用--connect-expired-password 选项
#-e 后面接的表示是在mysql里需要执行命令  execute 执行
#set password='Sanchuang123#';  修改root用户的密码为Sanchuan123#
mysql -uroot -p$tem_passwd --connect-expired-password   -e  "set password='Sanchuan123#';"


#检验上一步修改密码是否成功,如果有输出能看到mysql里的数据库,说明成功。
mysql -uroot -p'Sanchuang123#'  -e "show databases;"

(3) Run the script:

bash     onekey_install_mysql_binary_v3.sh

10. Determine whether the MySQL service is running?

1. Check the port: (1) yum install lsof net-tools -y
lsof -i:3306
(2) netstat -anplut|grep mysql
2. Check the process: ps aux|grep mysqld
3. Login: mysql -uroot -p

Conclusion:
If the above MySQL services can be started normally, then congratulations on the completion of MySQL installation.

Guess you like

Origin blog.csdn.net/zheng_long_/article/details/129542749