您的当前位置:首页正文

linux下使用yum安装mysql

2023-11-08 来源:画鸵萌宠网

4、Linux MySQL的几个重要目录  www.2cto.com  数据库目录         /var/lib/mysql/配置文件         /usr/share /mysql(mysql.server命令及配置文件)相关命令         /usr/bin(mysqladmin mysqldump等命令)启动脚本         /etc/rc.d/init.d/(启动脚本文件mysql的目录)

linux下使用yum安装mysql

标签:

小编还为您整理了以下内容,可能对您也有帮助:

Linux用yum方式安装mysql

本文详细描述了Linux如何用yum方式安装mysql以及如何修改mysql的数据文件存放位置

查看是否安装mysql: yum list installed | grep mysql有的话需要移除。 如::yum -y remove mysql-libs.x86_64

查看yum库上的mysql版本信息(CentOS系统需要正常连接网络)。 yum list|grep mysql

安装:yum -y install mysql-server mysql mysql-devel

安装完成后,使用命令mysql -version查看mysql的版本信息

启动mysql服务 /etc/init.d/mysqld start 或者 service mysqld restart

Mysql数据文件存放位置,默认为如下:

默认在:/var/lib/mysql/ 按目录存放 第一步,关闭mysql 第二步,移动/var/lib/mysql/目录下的数据库目录到自定义目录,如:/app/mysql 第三步,修改/etc/my.cnf中的datadir和socket的位置 datadir=/app/mysql 第四步,修改mysql启动脚本 #vi /etc/rc.d/init.d/mysqld get_mysql_option mysqld datadir "/var/lib/mysql"改为 get_mysql_option mysqld datadir "/app/mysql" 第五步, ln -s /app/mysql/mysql.sock /var/lib/mysql/mysql.sock 不加这一步,启动依然报错:var/lib/mysql/mysql.sock(2)无法启动 第六步,启动mysql服务

linux安装mysqllinux装mysql

linux虚拟机中如何安装mysql?

在linux虚拟机中,想要安装mySQL数据库,首先,虚拟机必须要能连上网络,然后通过网络下载mySQL安装包就可以正常安装了。如果无法连接网络,你可以用别的方式下载MySQL的安装包或者下载源码,然后把它复制到虚拟机中,再从心里集中安装就可以了。

linux怎么安装mysql数据库?

点击“Download”,下拉到最下面,选择社区版的进行下载,在跳转的新页面继续点击“Download”选择对应的操作系统版本和位数,下载对应的yum仓库,点击“Downloadnow”,在跳转的新页面中下载操作系统对应的版本在跳转的新的页面中会提示登录,选择直接下载上传到服务器并安装mysql的yum仓库

Linux yum安装过程图文详解

Yum可以从众多软件包仓库中搜索软件的依赖关系,因此可以减少由于依赖关系带来的问题。还有就是我们在使用图形界面时,在应用程序-添加删除软件下的浏览里是空的。如下图:

  

第一种方法:(推荐)

第一步:新建一个文件夹,并把光盘内的所有文件复制到这个文件夹里:

[root@localhost ~]# mkdir /yum

[root@localhost ~]# cp -rvf /misc/cd/* /yum

第二步:备份repodata文件。因为有四个文件夹里都有这个文件,所以都要备份。

[root@localhost ~]# mv /yum/Server/repodata /yum/Server/repodata.bak

[root@localhost ~]# mv /yum/VT/repodata /yum/VT/repodata.bak

[root@localhost ~]# mv /yum/Cluster/repodata /yum/Cluster/repodata.bak

[root@localhost ~]# mv /yum/ClusterStorage/repodata /yum/ClusterStorage/repodata.bak

第三步:安装工具包:

[root@localhost ~]# rpm -ivh /yum/Server/createrepo-0.4.11-3.el5.noarch.rpm

第四步:生成仓库数据库:

[root@localhost ~]# createrepo -g /yum/Server/repodata.bak/comps-rhel5-server-core.xml /yum/Server/

[root@localhost ~]# createrepo -g /yum/VT/repodata.bak/comps-rhel5-vt.xml /yum/VT/

[root@localhost ~]# createrepo -g /yum/Cluster/repodata.bak/ /yum/Cluster

[root@localhost ~]# createrepo -g /yum/ClusterStorage/repodata.bak/comps-rhel5-cluster-st.xml /yum/ClusterStorage/

第五步:查看仓库数据文件:

[root@localhost ~]# ls /yum/Server/repodata/

comps-rhel5-server-core.xml //这个文件软件包组的分类。

filelists.xml.gz other.xml.gz primary.xml.gz //这三个文件为软件包列表文件。

repomd.xml   //这个文件为MD5校验信息。

在/yum/VT /yum/Cluster /yum/ClusterStorage下面都有这几个文件,作用和这一样。如果想更新软件包,只需把下载完的软件包放在Server或者其他三个目录里,再使用第四步重新生成数据库文件即可。

第六步:客户端配置:主要修改下面红色的部分:

[root@localhost ~]# cp /etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/chenbin.repo

[root@localhost ~]# vi /etc/yum.repos.d/chenbin.repo

[rhel-Server]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///yum/Server

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-VT]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///yum/VT

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-Cluster]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///yum/Cluster

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-ClusterStorage]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///yum/ClusterStorage

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

第七步:查看:如图,已经出现软件列表了。

如果在上图中的编辑里选择软件存储库,就出现下图:

如果把这里的勾去掉,再次打开就没有软件列表了,同时在/etc/yum.repos.d/chenbin.repo配置文件下的enabled=0。

清除一下yum安装时的缓存:

[root@localhost ~]# yum clean all

安装一个软件试试:

[root@localhost ~]# rpm -ivh /yum/Server/httpd-2.2.3-22.el5.i386.rpm

warning: /yum/Server/httpd-2.2.3-22.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186

error: Failed dependencies:

libapr-1.so.0 is needed by httpd-2.2.3-22.el5.i386

libaprutil-1.so.0 is needed by httpd-2.2.3-22.el5.i386

因为依赖关系,所以不能安装。用如下命令安装:

[root@localhost ~]# yum install /yum/Server/httpd-2.2.3-22.el5.i386.rpm

系统会自动安装完成。Yum?载如下:

[root@localhost ~]# yum remove httpd。

1.2第二种方法:

第一步:同上,创建一个新文件夹,并把光盘的内容全部复制到该文件夹内:

[root@localhost ~]# mkdir /yum

[root@localhost ~]# cp -rvf /misc/cd/* /yum

第二步:安装工具包:

[root@localhost ~]# rpm -ivh /yum/Server/createrepo-0.4.11-3.el5.noarch.rpm

第三步:生成仓库数据库:

[root@localhost ~]# cd /yum

[root@localhost yum]# createrepo .      //注意后面的.

第四步:查看文件:文件作用同上:

[root@localhost yum]# ls /yum/repodata/

filelists.xml.gz other.xml.gz primary.xml.gz repomd.xml

第五步:客户端配置:

[root@localhost ~]# cp /etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/chenbin.repo

[root@localhost ~]# vi /etc/yum.repos.d/chenbin.repo

[rhel-chenbin]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///yum/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

清除yum安装时的缓存:

[root@localhost ~]# yum clean all

至此,yum安装完成,但使用这种方法安装后在应用程序-添加删除软件的列表是空的,但使用yum安装软件是可以的。

[root@localhost ~]# yum install /yum/Server/httpd-2.2.3-22.el5.i386.rpm

[root@localhost ~]# yum remove httpd

1.3第三种方法:

首先把光盘放入光驱内:

然后复制配置文件:

[root@localhost ~]# cp /etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/chenbin.repo

最后编辑配置文件:

[root@localhost ~]# vi /etc/yum.repos.d/chenbin.repo

[rhel-Server]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///misc/cd/Server

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-VT]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///misc/cd/VT

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-Cluster]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///misc/cd/Cluster

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-ClusterStorage]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///misc/cd/ClusterStorage

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

清除缓存:

[root@localhost ~]# yum clean all

这种方法安装后在应用程序-添加删除软件里也有列表。同样可以使用yum安装?载

[root@localhost ~]# yum install /misc/cd/Server/httpd-2.2.3-22.el5.i386.rpm

[root@localhost ~]# yum remove httpd

如果把光盘拿出后,在应用程序-添加删除软件就没有列表了,只要放入光盘就有。

1.4总结:YUM常用命令:

1.安装软件包:

yum install package

yum localinstall package 从本机目录安装软件包

yum groupinstall group 安装某个组件的全部软件包

2.更新软件包:

yum update package

yum check-update 列出所有可更新的软件包

yum list updates mysql* 查找mysql的更新

yum update 更新所有可更新的软件包

yum update mysql* 更新所有mysql的软件包

yum groupupdate group 更新某个组件的所有软件包

yum list 列出所有已安装和仓库中可用的软件包

yum list available 列出仓库中所有可用的软件包

yum list updates 列出仓库中比当前系统更新的软件包

yum list installed 列出已安装的软件包

yum list recent 列出新加入仓库的软件包

yum info 查询软件包信息

3.删除软件包:

yum remove package

yum groupremove group 删除某个组件的全部软件包

4.清除软件包

yum clean packages 清除遗留在缓存里的包文件

yum clean metadata 清除遗留在缓存里的元数据

yum clean headers 清除遗留在缓存里的头文件

yum clean all 清除包文件,元数据,头文件

5.搜索软件包:

yum search package

yum info package 查找一个软件包的信息

yum list package 列出包含指定信息的软件包

yum list installed 列出已安装的软件包

yum list extras 列出不是通过软件仓库安装的软件包

yum list *ttp* 列出标题包含ttp的软件包

yum list updates 列出可以更新的软件包

6.查找特定文件是由什么软件包提供的:

yum whatprovides filename

例子:

yum whatprovides httpd.conf

可用选项

–disalberepo=lib 禁用某个软件仓库

–enalberepo=lib 启用某个软件仓库

-C 禁用使用本机缓存的元数据

例子:

yum –disalberepo=livna|–enalberepo=livna install mplayer

yum -C info httpd

怎样在Linux环境下安装部署MySQL数据库系统

在Linux安装软件需要预先做好如下一些准备:准备好Linux操作系统如:CentOS7。配置好yum源。

完成上述准备后,就可以动手安装MySQL数据库了。主要安装步骤如下:

1. 禁用selinux

setenforce 0

2. 上传安装文件到Linux

3.解压rpm包

tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar

4.安装软件

yum install mysql-community-{libs,client,common,server}-*.rpm

5.启动mysql数据库初始化

systemctl start mysqld

6.修改vi /etc/my.cnf

添加:

[mysqld]

#可以在表中录入中文

character-set-server=utf8 #

explicit-defaults-for-timestamp

# 禁用当前密码认证策略,可以使用简单密码(生产环境不适用)

validate_password=0

7.重启mysql服务

systemctl restart mysqld

8.找临时登录密码

grep -i "temporary password" /var/log/mysqld.log

9.连接MySQL数据库

mysql -uroot -p 输入临时密码

10.修改root用户登录密码为简单密码(生产环境不适用)

alter user root@localhost identified by '';

11.配置MYSQL_PS1环境变量

修改家目录下:.bash_profile文件,添加

export MYSQL_PS1="\u@\h[\d]>"

12.使新环境变量生效

source /root/.bash_profile

13.重新连接mysql验证

mysql -uroot -p

除了上述安装方式以外,可能在公司中会遇到安装指定版本的需求,那么如何安装指定版本的MySQL数据呢?这时我们可以采用下载指定版本安装包进行安装的方式,主要步骤如下,假设CentOS7 linux最小安装,已经配置好yum。首先检查是否安装numactl包

rpm -qa|grep numactl

yum install numactl-libs-* # 如果没有安装需要安装。检查是否安装lio包

rpm -qa|grep lio

yum install lio-* # 如果没有安装需要安装

具体安装步骤如下:

* 禁用selinux

setenforce 0

* 上传安装文件到Linux

mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

* 创建mysql用户组和用户

groupadd -g 27 -r mysql

#-r创建系统账户,-M 不创建用户家目录 -N 不创建和用户名一样的用户组

useradd -M -N -g mysql -r -s /bin/false -c "MySQL Server" -u 27 mysql

id mysql

* 上传安装包到root家目录

* 解压二进制文件到/usr/local

tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local

* 解压目录改名为mysql

cd /usr/local

ls -l

mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql

* 环境变量中添加mysql/bin目录

vi /root/.bash_profile

修改PATH=/usr/local/mysql/bin:$PATH:$HOME/bin

添加 export MYSQL_PS1="\u@\h[\d]>"

source /root/.bash_profile

* 创建/usr/local/mysql/etc/my.cnf选项文件 (也可以使用默认的/etc/my.cnf选项文件)

mkdir -p /usr/local/mysql/etc

mkdir -p /usr/local/mysql/mysql-files

* 编辑选项文件my.cnf填写默认选项

vi /usr/local/mysql/etc/my.cnf

[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/usr/local/mysql/data/mysql.sock

log-error=/usr/local/mysql/data/mysqld.err

pid-file=/usr/local/mysql/data/mysqld.pid

secure_file_priv=/usr/local/mysql/mysql-files

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

Explicit-defaults-for-timestamp

character-set-server=utf8

[mysql]

socket=/usr/local/mysql/data/mysql.sock

* 初始化数据目录

cd /usr/local/mysql

mkdir data

chmod 750 data

chown mysql:mysql data

* 初始化数据库

cd /usr/local/mysql

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

* 使用systemd管理mysql

例如:systemctl {start|stop|restart|status} mysqld

cd /usr/lib/systemd/system

touch mysqld.service

chmod 644 mysqld.service

vi mysqld.service

# 添加以下内容

[Unit]

Description=MySQL Server

Documentation=man:mysqld(7)

Documentation=http://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

Type=forking

PIDFile=/usr/local/mysql/data/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.

TimeoutSec=0

# Start main service

ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --daemonize --pid-file=/usr/local/mysql/data/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation

EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit

LimitNOFILE = 65535

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

以上内容中注意:The --pid-file option specified in the my.cnf configuration file is ignored by systemd.

默认:LimitNOFILE = 5000,如果连接数(max_connection)需要调大,可以将LimitNOFILE 设置为最大65535

* 创建mysql.conf文件

cd /usr/lib/tmpfiles.d

#Add a configuration file for the systemd tmpfiles feature. The file is named mysql.conf and is placed in /usr/lib/tmpfiles.d.

cd /usr/lib/tmpfiles.d

touch mysql.conf

chmod 644 mysql.conf

* mysql.conf添加内容

vi mysql.conf

添加以下语句:

d /usr/local/mysql/data 0750 mysql mysql -

* 使新添加的mysqld服务开机启动

systemctl enable mysqld.service

* 手动启动mysqld

systemctl start mysqld

systemctl status mysqld

* 获得mysql临时登录密码

cat /usr/local/mysql/data/mysqld.err | grep "temporary password"

* 客户端登录连接mysql服务器

mysql -uroot -p

输入临时密码

* 修改MySQL用户root@localhost密码

mysql> alter user root@localhost identified by ''; #此处为了方便设置为空密码

* 测试新密码连接MySQL服务

mysql -uroot -p

至此,我们就完成了在Linux环境下安装MySQL的任务。通过这两种方式我们可以体会到在Linux环境下安装软件的基本思路及方法。

Top