当前位置:首页 > 经验

怎么在linux部署mysql linux安装mysql命令步骤

确认linux对应的版本:

cat /proc/version

uname -a

lsb_release -a

cat /etc/redhat-release

cat /etc/issue

linux系统安装mysql的详细步骤

这个是内核的版本:

3.10.0-1062.9.1.el7.x86_64

选择操作系统版本:

linux系统安装mysql的详细步骤

linux系统安装mysql的详细步骤

linux系统安装mysql的详细步骤

2.解压mysql的tar格式文件

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

运行上述命令,得到如下结果,有8个文件包:

linux系统安装mysql的详细步骤

也可以创建一个文件夹,在同一个子目录下解压。

3.安装解压的rpm安装包

然后我们可以用rpm -ivh命令来进行安装,注意安装顺序,因为这些包的安装是相互依赖的:必须安装(注意顺序)

rpm -ivh mysql-community-common-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-8.0.20-1.el7.x86_64.rpm
非必要安装(注意顺序)

rpm -ivh mysql-community-libs-compat-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-embedded-compat-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-devel-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-test-8.0.20-1.el7.x86_64.rpm安装过程中可能会报以下错误:

出现问题:error:

Failed dependencies:

libnuma.so.1()(64bit) is needed by mysql-community-server-8.0.13-1.el7.x86_64 libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-8.0.13-1.el7.x86_64 libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-8.0.13-1.el7.x86_64

解决办法:

yum install numactl

出现问题:error:

Failed dependencies:pkgconfig(openssl) is needed by mysql-community-devel-8.0.13-1.el7.x86_64

解决办法:

yum install openssl-devel.x86_64 openssl.x86_64 -y

出现问题:error:

Failed dependencies:perl(Data::Dumper) is needed by mysql-community-test-8.0.13-1.el7.x86_64

解决办法:

yum -y install autoconf

出现问题:error:

Failed dependencies:perl(JSON) is needed by mysql-community-test-8.0.13-1.el7.x86_64

解决办法:

yum install perl.x86_64 perl-devel.x86_64 -y

yum install perl-JSON.noarch -y

出现问题:error:

error: Failed dependencies:libaio.so.1()(64bit) is needed by MySQL-server-5.5.25a-1.rhel5.x86_64libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.5.25a-1.rhel5.x86_64

libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.5.25a-1.rhel5.x86_64

解决办法:

yum install libaio

以上我们的MySQL就安装好了,下面可以直接使用了。

4.使用数据库

  • 初始化数据库

mysqld –initialize –console目录授权,不授权的话MySQL没有写入权限,会启动失败

所以在初始化之前,记得授权,命令为:chown -R mysql:mysql /var/lib/mysql/启动msyql服务

命令:systemctl start mysqld停止MySQL命令:

service mysqld stop查看msyql服务的状态

service mysqld status

linux系统安装mysql的详细步骤

当看到Active后面是active(runing)说明启动成功了

4.修改数据库密码

当我们输入mysql -u root -p需要输入密码,我们可以去mysqld.log里面查看一下临时密码:

cat /var/log/mysqld.log

  • 下面我们就可以使用你的临时密码登录数据库

linux系统安装mysql的详细步骤

画线的部分就是安装好生成的初始密码

mysql -u root -p+回车
输入临时密码

修改命令:alter USER ‘root’@’localhost’ IDENTIFIED BY ‘新密码(必须包含:数字大小写字母特殊字符,长度最小为8位)’;

后面一定要加分号,不然无效

然后ctrl+d退出,重新进入就可以了,

输入命令

show databases;

use mysql;

正常就可以了

声明:此文信息来源于网络,登载此文只为提供信息参考,并不用于任何商业目的。如有侵权,请及时联系我们:fendou3451@163.com
标签:

  • 关注微信

相关文章