Linux离线安装mysql5.7

1.基本描述

有时候在内网中linux无法在线安装mysql,因此需要手动安装,这个过程比较麻烦。

2.准备工作

系统centos7、mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz

  1. 官网下载压缩包
    链接: https://dev.mysql.com/downloads/mysql/
    选择linux通用64位,5.7.40
    在这里插入图片描述
3.安装过程

1)根据自己需要选择在root账号安装mysql,也可以选择其他账户,首先将mysql解压到安装目录下。

[root@master datasoft]# tar -zxvf mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz

2)将解压的目录更名为mysql

[root@master datasoft]# mv mysql-5.7.40-linux-glibc2.12-x86_64 mysql

3)给mysql目录添加权限,通常来说是直接创建mysql用户然后,添加权限,不过我自己觉得麻烦是直接给mysql目录用root账户

#这里演示创建mysql用户的操作
#添加mysql组和msyql用户
[root@master datasoft]# groupadd mysql
[root@master datasoft]# useradd -s /sbin/nologin -r -g mysql mysql
[root@master datasoft]# chown -R mysql:mysql /root/datasoft/mysql
#-s:指定用户登入后所使用的shell 
#-r:系统级用户
#-g:所属分组为mysql

#我自己是直接用root用户,不需要创建
[root@master datasoft]# chown -R root:root /root/datasoft/mysql

4)在mysql目录中创data和logs目录

[root@master mysql]# mkdir {data,logs}

5)修改/etc/my.cnf文件,有的系统可能还要创建/etc/my.cnf.d文件否则会报错找不到该目录

[root@master mysql]# chown 777 /etc/my.cnf
[root@master mysql]# vim /etc/my.cnf

[mysqld]
character_set_server=utf8
character_set_server=utf8 
init_connect='SET NAMES utf8' 
basedir=/root/datasoft/mysql 
datadir=/root/datasoft/mysql/data 
socket=/root/datasoft/mysql/mysql.sock
#开启ip绑定 
#bind-address = 0.0.0.0 
log_timestamps = SYSTEM 
open_files_limit=30000 
max_connections=3000 
#控制其通信缓冲区的最大长度 
max_allowed_packet=256M
#设置忽略大小写(简单来说就是sql语句是否严格),默认库名表名保存为小写, 不区分大小写
lower_case_table_names = 1 
#Disabling symbolic-links is recommended to prevent assorted security risks 
symbolic-links=0
[mysqld_safe] 
log-error=/root/datasoft/mysql/logs/mysqld.log 
pid-file=/root/datasoft/mysql/data/mysqld.pid

[client] 
socket=/root/datasoft/mysql/mysql.sock 
#default-character-set=utf8
# include all files from the config directory
!includedir /etc/my.cnf.d

6)当我们把这些都配置好,就可以初始化mysql了,basedir为我们的mysql目录,datadir为我们创建的保存数据的目录。初始化后会打印出初始密码,如果忘记了可以清空datadir目录重新执行初始化。

[root@master mysql]# ./bin/mysqld --initialize --user=root --basedir=/root/datasoft/mysql/ --datadir=/root/datasoft/mysql/data/

7)复制启动脚本到资源目录,并修改//etc/rc.d/init.d/mysqld文件

[root@master mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@master mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@master mysql]# vim /etc/rc.d/init.d/mysqld
...
basedir=/root/datasoft/mysql
datadir=/root/datasoft/mysql/data
...
if test -x $bindir/mysqld_safe
then
  # Give extra arguments to mysqld with the my.cnf file. This script
  # may be overwritten at next upgrade.
  $bindir/mysqld_safe --user=root(在此处添加--user=root)  --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
  wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
  ...

8)在/etc/profile添加环境变量

[root@master mysql]# vim /etc/profile
...
export MYSQL_HOME=/root/datasoft/mysql
export PATH=$PATH:$MYSQL_HOME/bin
...

9)启动并登陆mysql,密码就是初始化给的密码

[root@master mysql]# service mysqld start
[root@master mysql]# mysql -uroot -p******
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password('123456') where user='root'
and host='localhost';
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;#允许远程连接
mysql> flush privileges;
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值