CentOS 7 下使用yum安装MySQL5.7
1、卸载 先停掉mysql进程 没有安装过的可以直接跳过
查看启动的端口方式:netstat -ntlp
如果存在就用 彻底杀死进程命令 kill -9 2040
然后在将其卸载 执行命令查询mysql相关的文件: rpm -qa|grep -i mysql
用命令 yum -y remove
yum -y remove mysql-community-client-5.6.38-2.el7.x86_64
卸载不掉的用 rpm -ev
依次卸载 直到没有
镜像加快下载速度
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
1、下载mysql源安装包:
[root@localhost ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
提示:如果用不了wget命令,需要:yum install wget
2、安装mysql源:
[root@localhost ~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
3、检查是否安装成功:
[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"
4、修改默认安装版本:
[root@localhost ~]# vi /etc/yum.repos.d/mysql-community.repo
5.5源 & 5.6源:
enabled=0
gpgcheck=1
5.7源:
enabled=1
gpgcheck=0
5、安装mysql:
[root@localhost ~]# yum install mysql-community-server
[root@localhost ~]# yum install -y mysql-connector-java
6、启动服务:
[root@localhost ~]# systemctl start mysqld
7、查看服务状态:
[root@localhost ~]# systemctl status mysqld
8、设置开机自动启动:
[root@localhost ~]# chkconfig mysqld on
9、修改默认密码:
查看默认密码:[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
利用默认密码先登录进去:
[root@localhost ~]# mysql -u root -p
设置密码长度:
mysql> set global validate_password_policy=LOW;
mysql> set global validate_password_length=4;
设置密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
10、开放远程登录权限:
mysql> grant all privileges on *.* to '用户名'@'%'identified by '密码' with grant option;
让权限生效:
mysql> flush privileges;
11、查看也存在的数据库:
mysql> show databases;