相关推荐recommended
Linux下载mysql(Centos7)
作者:mmseoamin日期:2024-03-20

1.检查本机是否下载过mysql

[root@localhost ~]# rpm -qa|grep -i mysql

如果未下载过,则为以下情形

Linux下载mysql(Centos7),在这里插入图片描述,第1张

如已下载,会有目录变化

Linux下载mysql(Centos7),在这里插入图片描述,第2张

如需删除,执行指令

[root@localhost /]# rpm -e --nodeps mysql-libs-5.7.41-1.el7.x86_64

之后再次执行指令,查看是否删除

2.下载mysql

下载官方的MySQL包

[root@localhost mysql]# wget https://repo.mysql.com/mysql57-community-release-el7.rpm

Linux下载mysql(Centos7),在这里插入图片描述,第3张

安装mysql包

[root@localhost mysql]# yum -y install mysql57-community-release-el7.rpm

Linux下载mysql(Centos7),在这里插入图片描述,第4张

安装mysql

[root@localhost mysql]# yum -y install mysql-community-server 

出现报错

Linux下载mysql(Centos7),在这里插入图片描述,第5张

解决方法:禁掉GPG验证检查

[root@localhost mysql]# yum -y install mysql-community-server --nogpgcheck

Linux下载mysql(Centos7),在这里插入图片描述,第6张

启动mysql服务

[root@localhost mysql]# systemctl start mysqld.service

查看运行状态

[root@localhost mysql]# service mysqld status

Linux下载mysql(Centos7),在这里插入图片描述,第7张

上图显示即为启动成功

查看密码

[root@localhost mysql]# grep 'password' /var/log/mysqld.log

Linux下载mysql(Centos7),在这里插入图片描述,第8张

密码为host:后的部分

进入数据库

可直接复制上述密码进入数据库

[root@localhost mysql]# mysql -u root -p

Linux下载mysql(Centos7),在这里插入图片描述,第9张

quit退出

Linux下载mysql(Centos7),在这里插入图片描述,第10张

更改密码

[root@localhost mysql]# mysqladmin -u root -p password

Linux下载mysql(Centos7),在这里插入图片描述,第11张

默认root密码不能过于简单,否则会出现ERROR,可先设置免密登录,再修改密码

设置免密登录

vim /etc/my.cnf文件;

在[mysqld]后添加skip-grant-tables(登录时跳过权限检查)

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

Linux下载mysql(Centos7),在这里插入图片描述,第12张

重启mysql服务,进入mysql

[root@localhost mysql]# systemctl restart mysqld
[root@localhost mysql]# mysql -u root -p

输入任意密码进入

输入 show databases;

Linux下载mysql(Centos7),在这里插入图片描述,第13张

切换到mysql数据库

Linux下载mysql(Centos7),在这里插入图片描述,第14张

修改密码为root

update user set authentication_string=password('root') where user='root';

密码也可以设置为其他值

Linux下载mysql(Centos7),在这里插入图片描述,第15张

编辑 my.cnf 文件,注释掉之前增加的那行

Linux下载mysql(Centos7),在这里插入图片描述,第16张

重启服务

[root@localhost mysql]# systemctl restart mysqld

使用密码root重新进入mysql

Linux下载mysql(Centos7),在这里插入图片描述,第17张

Linux下的mysql安装成功