基于Centos7 安装mysql5.7(docker环境下离线安装)

本文主要介绍了在基于centos7环境下安装mysql5.7。.
其中

  • centos7使用docker环境拉取。
  • mysql包为mysql-5.7.31-el7-x86_64.tar.gz

正文开始:

  • 下载mysql安装包,下载地址:https://dev.mysql.com/downloads/mysql/5.7.html
    在这里插入图片描述
  • 选择下载的文件
    在这里插入图片描述
  • 上传到服务器/usr/local 目录下
[root@cfbdbe8f540b /]# cd /usr/local/
[root@cfbdbe8f540b local]# ls
bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@cfbdbe8f540b local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.31-el7-x86_64.tar.gz  sbin  share  src

  • 解压文件
[root@cfbdbe8f540b local]# tar zxvf mysql-5.7.31-el7-x86_64.tar.gz 
  • 修改文件名
[root@cfbdbe8f540b local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.31-el7-x86_64  mysql-5.7.31-el7-x86_64.tar.gz  sbin  share  src
[root@cfbdbe8f540b local]# mv mysql-5.7.31-el7-x86_64 mysql
[root@cfbdbe8f540b local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  mysql-5.7.31-el7-x86_64.tar.gz  sbin  share  src
[root@cfbdbe8f540b local]# rm -rf mysql-5.7.31-el7-x86_64.tar.gz 
  • 创建data目录
[root@cfbdbe8f540b local]# mkdir -p mysql/data
  • 创建mysql用户组和用户
[root@cfbdbe8f540b local]# groupadd mysql
[root@cfbdbe8f540b local]# useradd mysql -g mysql
  • 修改mysql文件所属用户和用户组
[root@cfbdbe8f540b local]# chown -R mysql.mysql /usr/local/mysql
  • 创建my.cnf文件
[root@cfbdbe8f540b local]# vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid

  • 初始化数据
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

如果出先如下错误

2020-07-17 01:51:49 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-07-17 01:51:49 [ERROR]   Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2020-07-17 01:51:49 [ERROR]   Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

-- server log end --

使用以写命令

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

如果出现上述错误,执行以下命令

yum -y install numactl
yum -y install  libaio

或者下载离线rmp包,执行安装
libaio-0.3.109-13.el7.x86_64.rpm
numactl-devel-2.0.12-9.el8.x86_64.rpm

[root@ba0de71b3e99 local]# rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
warning: libaio-0.3.109-13.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:libaio-0.3.109-13.el7            ################################# [100%]

[root@ba0de71b3e99 local]# rpm -ivh numactl-libs-2.0.12-5.el7.x86_64.rpm  
warning: numactl-libs-2.0.12-5.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:numactl-libs-2.0.12-5.el7        ################################# [100%]

安装完成后,在执行上一步命令,发现执行成功。

[root@ba0de71b3e99 local]# /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
2020-07-17 02:53:01 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-07-17 02:53:06 [WARNING] The bootstrap log isn't empty:
2020-07-17 02:53:06 [WARNING] 2020-07-17T02:53:01.958497Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

  • 将mysql加入服务,并启动
[root@ba0de71b3e99 local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@ba0de71b3e99 local]# /etc/init.d/mysql start
Starting MySQL. SUCCESS! 

  • 启动成功,连接测试,由于my.cnf中配置了免密码,输入密码直接为空即可
[root@ba0de71b3e99 local]# /usr/local/mysql/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

至此,mysql已经成功安装完成,并成功连接登陆

  • 设置root密码,并允许远程连接
mysql> use mysql;
Database changed
mysql> update user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> update user set host='%' where user = 'root';

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

至此,密码已经修改完成。
1、修改/etc/my.cnf配置文件,注释#skip-grant-tables
2、重启服务,/etc/init.d/mysql restart

  • 添加快捷方式
ln -s /usr/local/mysql/bin/mysql /usr/bin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值