Linux下安装MySQL

Posted badmanwm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下安装MySQL相关的知识,希望对你有一定的参考价值。

主流数据库服务软件(RDBMS):Oracle、DB2、mysql、MariaDB、SQL Server

开源数据库软件:MySQL、MariaDB

商业数据库软件:Oracle、DB2、SQL Server(不跨平台)

跨平台数据库软件:Oracle、MySQL


关系型数据库(RDBMS):必须按照预先设定好的结构去存储数据,并且数据之间可以关联操作查询;


MySQL安装

安装MySQL版本为5.7,Linux CentOS6系统

前往官网https://dev.mysql.com/downloads/mysql/5.7.html#downloads下载RPM Bundle

上传到服务器上,tar解压:

[[email protected] sh]# tar -xvf mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar
[[email protected] sh]# ls *.rpm
mysql-community-client-5.7.24-1.el6.x86_64.rpm
mysql-community-common-5.7.24-1.el6.x86_64.rpm
mysql-community-devel-5.7.24-1.el6.x86_64.rpm
mysql-community-embedded-5.7.24-1.el6.x86_64.rpm
mysql-community-embedded-devel-5.7.24-1.el6.x86_64.rpm
mysql-community-libs-5.7.24-1.el6.x86_64.rpm
mysql-community-libs-compat-5.7.24-1.el6.x86_64.rpm
mysql-community-server-5.7.24-1.el6.x86_64.rpm
mysql-community-test-5.7.24-1.el6.x86_64.rpm

其中:

mysql-community-server-5.7.24-1.el6.x86_64.rpm 主程序包,提供服务的主包

mysql-community-client-5.7.24-1.el6.x86_64.rpm 管理工具数据库

剩下的都是辅助功能软件包,开始安装MySQL5.7:

[[email protected] sh]# rpm -Uvh mysql-community-*.rpm  #升级安装mysql,发现依赖包
warning: mysql-community-client-5.7.24-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
     libnuma.so.1()(64bit) is needed by mysql-community-embedded-5.7.24-1.el6.x86_64
     libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-embedded-5.7.24-1.el6.x86_64
     libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-embedded-5.7.24-1.el6.x86_64
     libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.24-1.el6.x86_64
     libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.24-1.el6.x86_64
     libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.24-1.el6.x86_64
     libnuma.so.1()(64bit) is needed by mysql-community-test-5.7.24-1.el6.x86_64
     libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-test-5.7.24-1.el6.x86_64
     libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-test-5.7.24-1.el6.x86_64
     perl(JSON) is needed by mysql-community-test-5.7.24-1.el6.x86_64
    perl(Time::HiRes) is needed by mysql-community-test-5.7.24-1.el6.x86_64

[[email protected] sh]# yum -y install libnuma.so.1*  #安装依赖包
[[email protected] sh]# yum -y install perl-JSON    #安装依赖包
[[email protected] sh]# yum -y install perl-Time-HiRes    #安装依赖包
[[email protected] sh]# rpm -Uvh mysql-community-*.rpm  #再次执行,成功安装
[[email protected] sh]# rpm -qa | grep -i mysql    #查询MySQL是否安装成功
mysql-community-common-5.7.24-1.el6.x86_64
mysql-community-devel-5.7.24-1.el6.x86_64
mysql-community-libs-compat-5.7.24-1.el6.x86_64
mysql-community-libs-5.7.24-1.el6.x86_64
mysql-community-server-5.7.24-1.el6.x86_64
mysql-community-embedded-5.7.24-1.el6.x86_64
mysql-community-test-5.7.24-1.el6.x86_64
mysql-community-client-5.7.24-1.el6.x86_64
mysql-community-embedded-devel-5.7.24-1.el6.x86_64

首次安装完成后mysql会自动创建/var/lib/mysql数据库目录,数据库目录/var/lib/mysql下是没有任何文件的,首次启动数据库的时候会数据初始化,初始化成功后在数据库目录/var/lib/mysql下自动生成文件,每次启动或重启数据库时会加载数据库目录下的文件,如果数据库目录下文件丢失那么会导致服务起不来!

[[email protected] mysql]# service mysqld start  #启动mysql
初始化 MySQL 数据库:                                      [确定]
正在启动 mysqld:                                          [确定]
[[email protected] mysql]# service mysqld status  #查询服务状态
mysqld (pid  7745) 正在运行...
[[email protected] mysql]# pwd;ls;
/var/lib/mysql
auto.cnf         client-key.pem  ib_logfile1  mysql.sock.lock     server-cert.pem
ca-key.pem       ib_buffer_pool  ibtmp1       performance_schema  server-key.pem
ca.pem           ibdata1         mysql        private_key.pem     sys
client-cert.pem  ib_logfile0     mysql.sock   public_key.pem
[[email protected] mysql]# chkconfig mysqld on  #设置mysql为开启自启动
[[email protected] mysql]# chkconfig mysqld --list
mysqld             0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭


mysql服务相关参数

主配置文件:/etc/my.cnf

数据库目录:/var/lib/mysql(自动创建)

默认端口号:3306

进程名:mysqld

传输协议:TCP

进程所有者:mysql

进程所属组:mysql


使用RPM安装方式会自动创建用户mysql,组mysql,数据库目录的属主组都是mysql,因为要对数据库目录进行读写;

[[email protected] ~]# ls -ld /var/lib/mysql
drwxr-x--x. 5 mysql mysql 4096 12月  4 23:21 /var/lib/mysql


总结:

1、解压

[[email protected] sh]# tar -xvf mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar

2、装包,并且安装依赖包

[[email protected] sh]# rpm -Uvh mysql-community-*.rpm 

[[email protected] sh]# yum -y install libnuma.so.1* 

[[email protected] sh]# yum -y install perl-JSON

[[email protected] sh]# yum -y install perl-Time-HiRes

[[email protected] sh]# rpm -Uvh mysql-community-*.rpm 

3、启服务

[[email protected] mysql]# service mysqld start

4、开机自启

[[email protected] mysql]# chkconfig mysqld on





























以上是关于Linux下安装MySQL的主要内容,如果未能解决你的问题,请参考以下文章

linux下源代码搭建php环境之mysql

mysql查看版本的四种方法

Linux下基于源代码方式安装MySQL 5.6

linux下安装mysql

Linux平台下安装MySQL

下载mysql5.6源码在linux下安装