cmake二进制安装mysql_二进制安装MySQL

本文详细介绍了在Linux环境下手动下载、安装、配置MySQL 5.6的过程,包括依赖安装、解压、目录移动、软链接创建、用户与权限设置、配置文件拷贝、数据库初始化、环境变量配置、systemctl服务管理以及启动数据库的步骤。同时,还补充了如何在自定义目录下进行二进制安装,并解决启动问题。
摘要由CSDN通过智能技术生成

下载mysql包,也可以自己上传到机器

[root@db01 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

一.安装

1.安装依赖yum install -y ncurses-devel libaio-devel gcc gcc-c++glibc cmake autoconf2.解雅tgz的包

[root@db01~]# tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz3.移动目录

[root@db01~]# mv mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/

4.做软链接

[root@db01~]# ln -s /usr/local/mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql5.创建mysql用户

[root@db01~]# useradd mysql -s /sbin/nologin -M6.拷贝配置文件和启动脚本

[root@db01 ~]# cd /usr/local/mysql/support-files/

[root@db01 support-files]# cp my-default.cnf /etc/my.cnfcp: overwrite ‘/etc/my.cnf’?y

[root@db01 support-files]# cp mysql.server /etc/init.d/mysqld7.初始化数据库

[root@db01~]# cd /usr/local/mysql/scripts/[root@db01 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data--user: 指定用户--basedir: 指定安装目录--datadir: 指定数据目录

#初始化成功的标志是有两个ok,再看最后有没有error

二.配置环境和systemctl管理

8.配置环境变量

[root@db01 scripts]# vim/etc/profile.d/mysql.shexport PATH=/usr/local/mysql/bin:$PATH

[root@db01 scripts]# source/etc/profile9.配置systemctl管理mysql

[root@db01 scripts]# vim/usr/lib/systemd/system/mysqld.service

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

LimitNOFILE= 5000[root@db01 scripts]# systemctl daemon-reload

三.启动数据库

10.启动数据库

[root@db01 scripts]# systemctl start mysqld11.确认启动

[root@db01 scripts]#ps -ef | grepmysql

mysql12886 1 2 03:10 ? 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

root12921 10636 0 03:11 pts/1 00:00:00 grep --color=auto mysql12.进入mysql

[root@db01 scripts]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 1Server version:5.6.46MySQL Community Server (GPL)

Copyright (c)2000, 2019, 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 clearthe current input statement.

mysql>

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

四.想要使用二进制安装到指定的目录下时(补充)

1.安装依赖

2.解压包

3.创建自定义的目录

#例:/service

[root@db01 ~]# mkdir /service

4.移动目录并做软连接

[root@db01 ~]# mv mysql-5.6.46-linux-glibc2.12-x86_64 /service/[root@db01~]# ln -s /service/mysql-5.6.46-linux-glibc2.12-x86_64 /service/mysql

5.创建用户

[root@db01 ~]# useradd mysql -s /sbin/nologin -M

6.拷贝配置文件和启动脚本

[root@db01 ~]# cd /service/mysql/support-files/[root@db01 support-files]# cp my-default.cnf /etc/my.cnf

cp: overwrite'/etc/my.cnf'?y

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

7.初始化数据库

[root@db01 support-files]# cd /service/mysql/scripts/

[root@db01 scripts]# ./mysql_install_db --user=mysql --basedir=/service/mysql --datadir=/service/mysql/data

8.配置systemctl管理mysql

[root@db01 scripts]# vim /usr/lib/systemd/system/mysqld.service

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/service/mysql/bin/mysqld --defaults-file=/etc/my.cnf

LimitNOFILE= 5000[root@db01 scripts]# systemctl daemon-reload

[root@db01 scripts]# systemctl start mysqld

#这是你会发现 netstat -lntp 没有 3306端口

9.使用init 启动数据库,修改

[root@m01 scripts]# /etc/init.d/mysqld start

#启动失败,因为mysql文件中很多都是/usr/local/mysql,我们需要替换

[root@db01 mysql]# sed-i 's#/usr/local/mysql#/service/mysql#g' /etc/init.d/mysqld /service/mysql/bin/mysqld_safe

#修改配置文件

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

18 basedir = /service/mysql

19 datadir = /service/mysql/data

#再次启动

[root@db01 mysql]#/etc/init.d/mysqld start

Starting MySQL.Logging to'/service/mysql/data/db01.err'.

SUCCESS!

10.配置环境变量

[root@db01 scripts]# vim /etc/profile.d/mysql.shexport PATH=/service/mysql/bin:$PATH

[root@db01 mysql]# source/etc/profile

11.确认启动

[root@m01 scripts]# netstat -lntp

tcp60 0 :::3306 :::* LISTEN 12886/mysqld

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值