MySQL二进制安装

目录

1.准备

1.1操作系统版本:       

1.2 MySQL安装包5.7和8.0(二进制通用版)    

1.3远程连接工具:       

2.安装 MySQL(以8.0版本为例)

2.1本地上传安装包

2.2解压安装包 tar -xf

2.3设置软链接  ln -s  

2.4设置环境变量      

2.5创建MySQL用户和组      

2.6创建相关目录并修改权限    

2.7写配置文件

2.8初始化数据(initialize参数的异同)  

2.9 MySQL8.0服务启动脚本为mysql.server,路径:  

3.启动mysql服务    

4.查看MySQL服务是否启动

5.登录MySQL 

6.安装遇到的问题

6.1上传问题

6.2初始化数据问题

6.3查看端口问题


1.准备


1.1操作系统版本:       

 Linux version 3.10.0-1160.el7.x86_64

[root@localhost ~]# cat /proc/version
Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020

1.2 MySQL安装包5.7和8.0(二进制通用版)    

mysql-5.7.36-linux-glibc2.12-x86_64.tar

mysql-8.0.26-linux-glibc2.12-x86_64.tar

可直接在官网下载

1.3远程连接工具:       

Xshell 7

2.安装 MySQL(以8.0版本为例)


2.1本地上传安装包


上传至/opt目录下:

[root@localhost opt]# ll
total 1544308
-rw-r--r--. 1 root root 666559924 Mar 21 12:58 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
-rw-r--r--. 1 root root 914806904 Mar 21 12:58 mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

2.2解压安装包 tar -xf

[root@localhost opt]# tar -xf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
[root@localhost opt]# ll
total 1544308
-rw-r--r--. 1 root root 666559924 Mar 21 12:58 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 9 root root       129 Mar 21 15:45 mysql-8.0.26-linux-glibc2.12-x86_64
-rw-r--r--. 1 root root 914806904 Mar 21 12:58 mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

2.3设置软链接  ln -s  

[root@localhost opt]# ln -s /opt/mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql
[root@localhost opt]# cd /usr/local/mysql
[root@localhost mysql]# ll
total 284
drwxr-xr-x.  2 7161 31415   4096 Jul  1  2021 bin
drwxr-xr-x.  2 7161 31415     55 Jul  1  2021 docs
drwxr-xr-x.  3 7161 31415    282 Jul  1  2021 include
drwxr-xr-x.  6 7161 31415    201 Jul  1  2021 lib
-rw-r--r--.  1 7161 31415 276551 Jul  1  2021 LICENSE
drwxr-xr-x.  4 7161 31415     30 Jul  1  2021 man
-rw-r--r--.  1 7161 31415    666 Jul  1  2021 README
drwxr-xr-x. 28 7161 31415   4096 Jul  1  2021 share
drwxr-xr-x.  2 7161 31415     77 Jul  1  2021 support-files

2.4设置环境变量      


在/etc/profile文件的最后一行添加:export PATH=/usr/local/mysql/bin:$PATH,并使用source命令使得文件生效:

[root@localhost mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
[root@localhost mysql]# tail -3 /etc/profile
unset i
unset -f pathmunge
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost mysql]# source /etc/profile

mysql -V 查看MySQL的版本:

[root@localhost mysql]# mysql -V
mysql  Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL)

2.5创建MySQL用户和组      

[root@localhost mysql]# useradd mysql
[root@localhost mysql]# id mysql
uid=1001(mysql) gid=1001(mysql) groups=1001(mysql)

2.6创建相关目录并修改权限    

[root@localhost mysql]# mkdir -p /data/mysql80/data
[root@localhost mysql]# chown -R mysql.mysql /data/*

2.7写配置文件

[root@localhost mysql]# vim /etc/my.cnf

基本配置

[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql80/data
server_id=1
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock

2.8初始化数据(initialize参数的异同)  

             
方法一:--initialize 初始化分配管理员一个临时密码

mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql80/data:

[root@localhost mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql80/data
2022-03-21T11:39:46.872524Z 0 [System] [MY-013169] [Server] /opt/mysql-8.0.26-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 16717
2022-03-21T11:39:46.881127Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-21T11:39:48.493066Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-21T11:39:49.432499Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-03-21T11:39:49.432740Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-03-21T11:39:49.474412Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: QeZ<uwCIr4eg

最后一行临时密码信息如下:
2022-03-21T11:39:49.474412Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: QeZ<uwCIr4eg
管理员临时密码为:QeZ<uwCIr4eg

查看初始化后生成的文件:

[root@localhost mysql]# cd /data/mysql80/data
[root@localhost data]# ll
total 179640
-rw-r-----. 1 mysql mysql       56 Mar 21 19:52 auto.cnf
-rw-------. 1 mysql mysql     1680 Mar 21 19:52 ca-key.pem
-rw-r--r--. 1 mysql mysql     1112 Mar 21 19:52 ca.pem
-rw-r--r--. 1 mysql mysql     1112 Mar 21 19:52 client-cert.pem
-rw-------. 1 mysql mysql     1676 Mar 21 19:52 client-key.pem
-rw-r-----. 1 mysql mysql   196608 Mar 21 19:52 #ib_16384_0.dblwr
-rw-r-----. 1 mysql mysql  8585216 Mar 21 19:52 #ib_16384_1.dblwr
-rw-r-----. 1 mysql mysql     6082 Mar 21 19:52 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 Mar 21 19:52 ibdata1
-rw-r-----. 1 mysql mysql 50331648 Mar 21 19:52 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 Mar 21 19:52 ib_logfile1
drwxr-x---. 2 mysql mysql        6 Mar 21 19:52 #innodb_temp
drwxr-x---. 2 mysql mysql      143 Mar 21 19:52 mysql
-rw-r-----. 1 mysql mysql 28311552 Mar 21 19:52 mysql.ibd
drwxr-x---. 2 mysql mysql     8192 Mar 21 19:52 performance_schema
-rw-------. 1 mysql mysql     1676 Mar 21 19:52 private_key.pem
-rw-r--r--. 1 mysql mysql      452 Mar 21 19:52 public_key.pem
-rw-r--r--. 1 mysql mysql     1112 Mar 21 19:52 server-cert.pem
-rw-------. 1 mysql mysql     1676 Mar 21 19:52 server-key.pem
drwxr-x---. 2 mysql mysql       28 Mar 21 19:52 sys
-rw-r-----. 1 mysql mysql 16777216 Mar 21 19:52 undo_001
-rw-r-----. 1 mysql mysql 16777216 Mar 21 19:52 undo_002

方法二:--initialize-insecure 初始化管理员的密码为空
先删除方法一生成的文件 rm -rf /data/mysql80/data/*:

[root@localhost data]# rm -rf /data/mysql80/data/*
[root@localhost data]# ll
total 0

初始化

mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql80/data:

[root@localhost data]# mysqld --initialize-insecure  --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql80/data
2022-03-21T11:57:15.861843Z 0 [System] [MY-013169] [Server] /opt/mysql-8.0.26-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 16837
2022-03-21T11:57:15.866614Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-21T11:57:16.680582Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-21T11:57:17.269624Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-03-21T11:57:17.269860Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-03-21T11:57:17.333950Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

最后一行 root@localhost is created with an empty password:管理员的密码为空

2.9 MySQL8.0服务启动脚本为mysql.server,路径:  

 
/usr/local/mysql/support-files/mysql.server

[root@localhost data]# cd /usr/local/mysql/support-files
[root@localhost support-files]# ll
total 20
-rwxr-xr-x. 1 7161 31415  1061 Jul  1  2021 mysqld_multi.server
-rw-r--r--. 1 7161 31415  2027 Jul  1  2021 mysql-log-rotate
-rwxr-xr-x. 1 7161 31415 10576 Jul  1  2021 mysql.server

可以将其拷贝到存放系统服务的管理(启动与停止)脚本/etc/init.d目录下:

[root@localhost support-files]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

3.启动mysql服务    


方法一,以脚本方式启动:

[root@localhost support-files]# ./ mysql.server start

或者

[root@localhost support-files]# sh mysql.server start
Starting MySQL.. SUCCESS!

方法二,以sys-v启动:                

[root@localhost support-files]# service mysqld restart
Shutting down MySQL. SUCCESS! 
Starting MySQL.. SUCCESS!

方法三,以systemd启动:
前提:先将启动脚本拷贝到/etc/init.d目录下,然后通过以下命令

systemctl enable mysqld:

[root@localhost support-files]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on

将其转换为systemd方式:

[root@localhost support-files]# systemctl restart mysqld

4.查看MySQL服务是否启动

方法一:netstat -tulnp 查看端口

[root@localhost support-files]# systemctl restart mysqld
[root@localhost support-files]# netstat -tulnp
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      1350/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1582/master         
tcp6       0      0 :::33060                :::*                    LISTEN      22325/mysqld        
tcp6       0      0 :::3306                 :::*                    LISTEN      22325/mysqld

  方法二:ps -ef | grep mysqld 查看进程

[root@localhost support-files]# ps -ef | grep mysqld
root      16979      1  0 20:09 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql80/data --pid-file=/data/mysql80/data/localhost.localdomain.pid
mysql     17133  16979  2 20:09 pts/0    00:00:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql80/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/data/mysql80/data/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root      17182   1829  0 20:10 pts/0    00:00:00 grep --color=auto mysqld

5.登录MySQL 


因为后面是用--initialize-insecure参数初始化数据,管理员密码为空,登陆时在命令行敲入 mysql 然后回车即可登录

[root@localhost support-files]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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.

mysql> 

6.安装遇到的问题


6.1上传问题

[root@localhost opt]# rz -E
-bash: rz: command not found

上传失败,因为没有安装 lrzsz
解决办法: yum -y install lrzsz

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

6.2初始化数据问题

[root@localhost mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql80/data
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

报错原因: Linux系统中缺少libaio-devel 软件包
解决:安装软件包即可

yum -y install libaio-devel

6.3查看端口问题

[root@localhost support-files]# netstat -tulnp
-bash: netstat: command not found

netstat命令不可用,需要安装net-tools解决:

yum -y install net-tools
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值