Centos 下mysql数据库完整安装过程(亲试可用)

发布于:2022-11-10 ⋅ 阅读:(554) ⋅ 点赞:(0)

1. 检查系统自带的Mysql,并卸载自带的版本

yum list installed |grep mysql

2、卸载系统自带的mysql及其依赖 

yum -y remove mysql-libs.x86_64

每次卸载后需要使用1命令再看下还有没有残余,都卸载(即删除掉)

3、CentOS添加rpm源,并且选择较新的源

1)下载rpm包

wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm --no-check-certificate

2)安装本地mysql源

yum localinstall mysql-community-release-el6-5.noarch.rpm

3)验证是否安装成功

yum repolist all | grep mysql

4)修改默认版本为5.7

方法一:

执行:

yum-config-manager --disable mysql56-community

yum-config-manager --enable mysql57-community-dmr

如上操作,是把5.6禁用,把5.7启用

此法,会有异常情况:

如果执行命令出现如下错误:

-bash: yum-config-manager: command not found

可用执行如下命令解决,然后继续上面的操作命令:

yum -y install yum-utils

方法二:

直接编辑配置文件,简单、直接,基本不会出现错误~

vi /etc/yum.repos.d/mysql-community.repo 

把5.6的enabled=0

把5.7的enabled=1

然后保存就ok

# Enable to use MySQL 5.5

[mysql55-community]

name=MySQL 5.5 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/

enabled=0

gpgcheck=1

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

# Enable to use MySQL 5.6

[mysql56-community]

name=MySQL 5.6 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/

enabled=0

gpgcheck=1

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

# Note: MySQL 5.7 is currently in development. For use at your own risk.

# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/

[mysql57-community-dmr]

name=MySQL 5.7 Community Server Development Milestone Release

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/

enabled=1

gpgcheck=1

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

此时,再执行:

yum repolist all | grep mysql

4. 安装mysql

执行如下命令:

yum install mysql-community-server

安装过程遇到报错

centos7 安装mysql5.7出现报错:libsasl2.so.2()(64bit)错误解决方法_大田测试录的博客-CSDN博客1、把这行中的6改为7## baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/修改/etc/yum.repos.d/mysql-community.repo 源文件。2、把gpgcheck=改为0。https://blog.csdn.net/weixin_38177508/article/details/127793061?spm=1001.2014.3001.5501

5、启动mysql

service mysqld start

启动过程报错

启动Mysql时报错Redirecting to /bin/systemctl start mysqld.service_大田测试录的博客-CSDN博客报错:Redirecting to /bin/systemctl start mysqld.service。在启动mysql时,执行。报错,不能进入Mysql。https://blog.csdn.net/weixin_38177508/article/details/127793179?spm=1001.2014.3001.5501

6、查看mysql服务状态

 service mysqld status

7、查看mysql 初始密码

mysql5.7之后初始密码不再默认为空

grep 'temporary password' /var/log/mysqld.log 

查看不到密码解决办法:

输入grep ‘temporary password‘ /var/log/mysqld.log无法查询到数据库的初始密码的解决方案_大田测试录的博客-CSDN博客我的mysqld.log中根本没有temporary password。原因:删除原来安装过的mysql残留的数据。再重新启动mysql,密码出现。https://blog.csdn.net/weixin_38177508/article/details/127793331?spm=1001.2014.3001.5502

8、命令行登录mysql ,并修改密码

1)登录之后 第一步必须先修改密码,

否则其他操作都执行不了。

mysql -u root -p

2)修改密码

alter user root@localhost identified by '新密码';

新修改的密码中 必须包含 大小写字母数字及符号

到这就结束了


网站公告

今日签到

点亮在社区的每一天
去签到