centOS 7 离线安装 MySQL 5.6

centOS 7 离线安装 MySQL 5.6

准备环境

1、离线 centOS 7(此处为 centOS 7 最小安装)

2、nginx 安装文件 (mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz 已放到下面的链接中,请自行下载或自己去官网下载最新版)

3、nginx 依赖包 (目前已放到 lib 目录中,可自行下载)

目前所有安装所需要的包和依赖都可去以下地址自行根据所对应软件进行下载

https://gitee.com/livekeys/linux-offline-installation-software.git

一、卸载 mariadb

查询之前是否有 mariadb ,有就将其删除,并删除以前的配置文件 /etc/my.cnf

[root@localhost ~]# rpm -qa | grep mariadb*
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e mariadb-libs --nodeps
[root@localhost ~]# rpm -qa | grep mariadb*
[root@localhost ~]# rm -f /etc/my.cnf
[root@localhost ~]#

二、安装依赖

将 lib 中的所有依赖上传到 linux 中,并用命令进行安装

[root@localhost lib]# yum -y localinstall *.rpm

三、安装 MySQL 5.6

1、解压并把文件复制到你想要安装的目录(此处我将 /opt/mysql 作为安装目录)

[root@localhost mysql_install]# tar -xzvf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql_install]# ls
lib  mysql-5.6.51-linux-glibc2.12-x86_64  mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql_install]# cp -R mysql-5.6.51-linux-glibc2.12-x86_64 /opt/mysql
[root@localhost mysql_install]# cd /opt/mysql
[root@localhost mysql]# ls
bin  data  docs  include  lib  LICENSE  man  mysql-test  README  scripts  share  sql-bench  support-files

2、新建 mysql 组和 mysql 用户,并将 mysql 目录更换成 mysql 用户组

[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -g mysql mysql
[root@localhost mysql]# cd ..
[root@localhost opt]# ls
mysql
[root@localhost opt]# chown -R mysql:mysql mysql
[root@localhost opt]# ll
total 0
drwxr-xr-x. 13 mysql mysql 191 Mar 23 01:42 mysql
[root@localhost opt]# cd mysql
[root@localhost mysql]# ll
total 224
drwxr-xr-x.  2 mysql mysql   4096 Mar 23 01:42 bin
drwxr-xr-x.  3 mysql mysql     18 Mar 23 01:42 data
drwxr-xr-x.  2 mysql mysql     55 Mar 23 01:42 docs
drwxr-xr-x.  3 mysql mysql   4096 Mar 23 01:42 include
drwxr-xr-x.  3 mysql mysql   4096 Mar 23 01:42 lib
-rw-r--r--.  1 mysql mysql 200256 Mar 23 01:42 LICENSE
drwxr-xr-x.  4 mysql mysql     30 Mar 23 01:42 man
drwxr-xr-x. 10 mysql mysql   4096 Mar 23 01:42 mysql-test
-rw-r--r--.  1 mysql mysql    566 Mar 23 01:42 README
drwxr-xr-x.  2 mysql mysql     30 Mar 23 01:42 scripts
drwxr-xr-x. 28 mysql mysql   4096 Mar 23 01:42 share
drwxr-xr-x.  4 mysql mysql   4096 Mar 23 01:42 sql-bench
drwxr-xr-x.  2 mysql mysql    136 Mar 23 01:42 support-files

3、新建 /var/lib/mysql 目录用于存放 mysq.sock(也可以新建其他的目录),并将该目录所属组更改成 myql

[root@localhost mysql]# mkdir /var/lib/mysql
[root@localhost mysql]# chown -R mysql:mysql /var/lib/mysql
[root@localhost mysql]# ls -al /var/lib/mysql
total 4
drwxr-xr-x.  2 mysql mysql    6 Mar 23 01:51 .
drwxr-xr-x. 26 root  root  4096 Mar 23 01:51 ..

4、进入 mysql 安装目录,进行初始化 mysql

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
Installing MySQL system tables...2022-03-23 01:53:51 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-03-23 01:53:51 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2022-03-23 01:53:51 0 [Note] /opt/mysql/bin/mysqld (mysqld 5.6.51) starting as process 13346 ...
2022-03-23 01:53:51 13346 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-03-23 01:53:51 13346 [Note] InnoDB: The InnoDB memory heap is disabled
2022-03-23 01:53:51 13346 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-03-23 01:53:51 13346 [Note] InnoDB: Memory barrier is not used
2022-03-23 01:53:51 13346 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-03-23 01:53:51 13346 [Note] InnoDB: Using Linux native AIO
2022-03-23 01:53:51 13346 [Note] InnoDB: Using CPU crc32 instructions
2022-03-23 01:53:51 13346 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2022-03-23 01:53:51 13346 [Note] InnoDB: Completed initialization of buffer pool
2022-03-23 01:53:51 13346 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2022-03-23 01:53:51 13346 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2022-03-23 01:53:51 13346 [Note] InnoDB: Database physically writes the file full: wait...
2022-03-23 01:53:51 13346 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2022-03-23 01:53:51 13346 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2022-03-23 01:53:51 13346 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2022-03-23 01:53:51 13346 [Warning] InnoDB: New log files created, LSN=45781
2022-03-23 01:53:51 13346 [Note] InnoDB: Doublewrite buffer not found: creating new
2022-03-23 01:53:51 13346 [Note] InnoDB: Doublewrite buffer created
2022-03-23 01:53:51 13346 [Note] InnoDB: 128 rollback segment(s) are active.
2022-03-23 01:53:51 13346 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-03-23 01:53:51 13346 [Note] InnoDB: Foreign key constraint system tables created
2022-03-23 01:53:51 13346 [Note] InnoDB: Creating tablespace and datafile system tables.
2022-03-23 01:53:51 13346 [Note] InnoDB: Tablespace and datafile system tables created.
2022-03-23 01:53:51 13346 [Note] InnoDB: Waiting for purge to start
2022-03-23 01:53:51 13346 [Note] InnoDB: 5.6.51 started; log sequence number 0
2022-03-23 01:53:51 13346 [Note] RSA private key file not found: /opt/mysql/data//private_key.pem. Some authentication plugins will not work.
2022-03-23 01:53:51 13346 [Note] RSA public key file not found: /opt/mysql/data//public_key.pem. Some authentication plugins will not work.
2022-03-23 01:53:51 13346 [Note] Binlog end
2022-03-23 01:53:51 13346 [Note] InnoDB: FTS optimize thread exiting.
2022-03-23 01:53:51 13346 [Note] InnoDB: Starting shutdown...
2022-03-23 01:53:53 13346 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OKFilling help tables...2022-03-23 01:53:53 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-03-23 01:53:53 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2022-03-23 01:53:53 0 [Note] /opt/mysql/bin/mysqld (mysqld 5.6.51) starting as process 13368 ...
2022-03-23 01:53:53 13368 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-03-23 01:53:53 13368 [Note] InnoDB: The InnoDB memory heap is disabled
2022-03-23 01:53:53 13368 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-03-23 01:53:53 13368 [Note] InnoDB: Memory barrier is not used
2022-03-23 01:53:53 13368 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-03-23 01:53:53 13368 [Note] InnoDB: Using Linux native AIO
2022-03-23 01:53:53 13368 [Note] InnoDB: Using CPU crc32 instructions
2022-03-23 01:53:53 13368 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2022-03-23 01:53:53 13368 [Note] InnoDB: Completed initialization of buffer pool
2022-03-23 01:53:53 13368 [Note] InnoDB: Highest supported file format is Barracuda.
2022-03-23 01:53:53 13368 [Note] InnoDB: 128 rollback segment(s) are active.
2022-03-23 01:53:53 13368 [Note] InnoDB: Waiting for purge to start
2022-03-23 01:53:53 13368 [Note] InnoDB: 5.6.51 started; log sequence number 1625977
2022-03-23 01:53:53 13368 [Note] RSA private key file not found: /opt/mysql/data//private_key.pem. Some authentication plugins will not work.
2022-03-23 01:53:53 13368 [Note] RSA public key file not found: /opt/mysql/data//public_key.pem. Some authentication plugins will not work.
2022-03-23 01:53:53 13368 [Note] Binlog end
2022-03-23 01:53:53 13368 [Note] InnoDB: FTS optimize thread exiting.
2022-03-23 01:53:53 13368 [Note] InnoDB: Starting shutdown...
2022-03-23 01:53:55 13368 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OKTo start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:/opt/mysql/bin/mysqladmin -u root password 'new-password'/opt/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'Alternatively you can run:/opt/mysql/bin/mysql_secure_installationwhich will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd . ; /opt/mysql/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd mysql-test ; perl mysql-test-run.plPlease report any problems at http://bugs.mysql.com/The latest information about MySQL is available on the web athttp://www.mysql.comSupport MySQL by buying support/licenses at http://shop.mysql.comNew default config file was created as /opt/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

4、复制和修改配置文件

[root@localhost mysql]# cp ./support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# chown mysql:mysql /etc/my.cnf
[root@localhost mysql]# chmod 644 /etc/my.cnf

my.cnf 配置文件内容如下:(这里根据自己的需求修改其他配置)

注意以下几点:

  • socket 写上面我们第三步新建的那个目录
  • basedir 为 mysql 安装目录
  • datadir 为数据目录(这里是 mysql 安装目录下的 data 目录)
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock[mysqld]
skip-name-resolve
#设置 13306 端口
port = 13306
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/opt/mysql
# 设置mysql数据库的数据的存放目录
datadir=/opt/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_name=1
max_allowed_packet=16M

5、复制启动脚本到资源目录

[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chown mysql:mysql /etc/rc.d/init.d/mysqld

6、修改启动脚本

[root@localhost mysql]# vim /etc/rc.d/init.d/mysqld

注:因为,我没有将 mysql 安装在 /usr/local/mysql 目录下,所以在启动文件里需要修改以下两个值

basedir=/opt/mysql
datadir=/opt/mysql/data

7、将 mysqld 服务加入到系统服务里面

[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --list mysqldNote: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.To see services enabled on particular target use'systemctl list-dependencies [target]'.mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

8、使用命令 systemctl 启动 mysql 服务(Active 状态为 active (running) 即为启动成功)

[root@localhost mysql]# systemctl start mysql
[root@localhost mysql]# systemctl status mysql
● mysqld.service - LSB: start and stop MySQLLoaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)Active: active (running) since Wed 2022-03-23 02:11:17 EDT; 5s agoDocs: man:systemd-sysv-generator(8)Process: 13452 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)CGroup: /system.slice/mysqld.service├─13463 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/opt/mysql/data --pid-file=/opt/mysql/data/lo...└─13688 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mys...Mar 23 02:11:16 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL...
Mar 23 02:11:16 localhost.localdomain mysqld[13452]: Starting MySQL.Logging to '/opt/mysql/data/localhost....r'.
Mar 23 02:11:17 localhost.localdomain mysqld[13452]: SUCCESS!
Mar 23 02:11:17 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.
Hint: Some lines were ellipsized, use -l to show in full.

9、将 mysql 客户端配置到环境变量中,并使配置生效

[root@localhost mysql]# vim /etc/profile
# 在末尾增加以下两行
export MYSQL_HOME=/opt/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@localhost mysql]# source /etc/profile

10、测试是否能连接 mysql

**注:**第一次登录不需要密码,直接回车就行

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.51 MySQL Community Server (GPL)Copyright (c) 2000, 2021, 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>

11、配置 root 账号的密码为 P@ssw0rd

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 -ADatabase changed
mysql> update user set password=password('P@ssw0rd') where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

12、设置远程主机登录

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 -ADatabase changed
mysql> grant all privileges on *.* to 'root'@'%' identified by 'P@ssw0rd' with grant option;
Query OK, 0 rows affected (0.00 sec)

13、重启 mysqld 服务并测试登录

[root@localhost ~]# systemctl restart mysql
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.51 MySQL Community Server (GPL)Copyright (c) 2000, 2021, 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 |
| test               |
+--------------------+
4 rows in set (0.00 sec)mysql>

至此,已完成 mysql 5.6 的安装

如有错误的地方,欢迎留言指正,谢谢!

centOS 7 安装 MySQL 5.6 离线安装相关推荐

  1. centos下安装mysql选什么版本_CentOS 7 安装MySQL 5.7 或安装指定版本MySQL-Go语言中文社区...

    1 摘要 目前(2019)年,MySQL 的最新版本为 MySQL 8.0 ,然而很多项目中依然使用的是 MySQL 5.7,个人开发环境中为了和线上项目数据库保持一致,也需要安装相同版本的 MySQ ...

  2. docker安装mysql主从视频教程_docker安装mysql主从

    docker安装mysql主从 启动主库: 1.docker run --name master -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5 ...

  3. centos7 安装英伟达驱动;cuda;docker离线安装;docker gpu离线安装;制作自己的cuda镜像;安装 容器中ssh协议

    原创不易,谢谢! centos7 安装英伟达驱动,cuda,docker安装,docker gpu安装,制作自己的cuda镜像,docker ssh协议 无论是笔记本还是台式电脑,这一步关键 参考资料 ...

  4. sdk linux 离线安装方法,Android SDK离线安装方法详解(加速安装)

    AndroidSDK在国内下载一直很慢··有时候通宵都下不了一点点,最后只有选择离线安装,现在发出离线安装地址和方法,希望对大家有帮助 一,首先下载SDK的安装包,android-sdk_r10-wi ...

  5. 如何安装mysql 5.6_如何安装MySQL 5.6?

    问题描述 我刚刚安装了Ubuntu 12.10(amd64),并希望安装最新版本的MySQL 5.6. 如果可能的话,我想安装(而不是升级)它"Debian Way"(即使用apt ...

  6. Linux环境下安装MySQL(源码安装)

    Linux环境下安装MySQL(源码安装) 1.事先从官网/国内镜像站点中下载源码安装包,上传至服务器: 2.安装开发工具和开发包(从5.5开始使用cmake编译) 3.创建用户和组 4.编译安装My ...

  7. Windows 安装 MySQL 8 zip版安装,及Windows MySQL多实例

    Windows  安装  MySQL 8 zip版安装,及Windows MySQL多实例 目录 一.下载MySQL压缩包 二.设置系统环境变量 三.解压并新建配置文件 四.注册 Windows 服务 ...

  8. linux中安装mysql步骤,Linux中安装MySql 5.7.21的详细操作步骤

    python基础01 Hello World! 摘要:简单的Hello Word! python 命令行 如已经安装python,那么在linux命令行中输入 $python 将进入python.乱吼 ...

  9. 离线安装nginx(包括离线安装gcc-g++环境,免费下载gcc离线安装包)

    离线安装nginx(包括离线安装gcc-g++环境) 有些时候我们的linux服务器无法连接公网的情况下就需要离线安装应用 检查电脑是否有gcc和gcc-c++环境 gcc -v g++ -v # 如 ...

最新文章

  1. 虚商烦恼多?不在怕的!你距离享受高效虚商控制台只差一步的距离
  2. 配置 Keepalived + LVS-DR模式, 实现高可用和负载均衡
  3. 学习笔记(二十二)—— 了解进程和线程
  4. html语言dl与ul,HTML中DL、UL、OL用哪个比较好
  5. 3 View - 状态保持 session
  6. python3的文件读写模式
  7. [Flex]Flex 3.0 and Adobe AIR 1.0正式版发布!
  8. 利用计算机进行绘制建筑图纸,工程计算机制图.pdf
  9. 转:毕业几年出来来的我们的生活
  10. 网页一键分享按钮HTML代码
  11. XMind中怎么导入图标?
  12. Linux操作系统之虚拟化
  13. Python编程PTA题解——验证“哥德巴赫猜想”
  14. java-day24
  15. STM32 cubeIDE 堆栈大小设置
  16. cf服务器优化,CFHD服务器优化后的效果 老版本技巧重现
  17. 最近读书得感悟 (二) 为自己工作的必要性
  18. DALLE·2(Hierarchical Text-Conditional Image Generation with CLIP Latents)
  19. windows 找不到文件'gpedit.msc'.请确定文件名是否正确后 windows10 家庭版 打不开组策略 不想更新 不想换版本
  20. 鸿蒙系统开发实战-开发一个聊天技巧软件堪称聊天神器

热门文章

  1. linear(): argument ‘input‘ (position 1) must be Tensor, not str
  2. uniapp上传图片压缩并转base64码、base64转图片路径
  3. msys2设置网络代理
  4. 产品经理们如何看待NPDP认证?你知道吗?
  5. 从头开始学语法 1:名词的分类
  6. Linux离线安Redis
  7. Cadence OrCAD Capture 复制粘贴电路时保持元器件自动编号的方法图文教程
  8. iOS获取手机的Mac地址
  9. R语言量化:KDJ指标的计算
  10. 今日更新【湖南大学】初试复试资料分享(附考研群)