centos7中安装mysql5.7.x详细教程

	由于centos7中默认的数据库是Mariadb,因此在安装mysql数据库之前需要先删除Mariadb!

1. 删除Mariadb

(1) 查看centos中有没有安装Mariadb、mysql

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

(2) 卸载centos7中的Mariadb库

 [root@localhost ~]# rpm -qa|grep mariadb|xargs rpm -e --nodeps

(3) 删除遗留目录

[root@localhost ~]#	ls /etc/my.cnf
[root@localhost ~]#	ll /var/lib/mysql/
[root@localhost ~]#	rm –rf /etc/my.cnf
[root@localhost ~]#	rm –rf /var/lib/mysql/

2. 下载mysql的的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

在这里插入图片描述

  可能遇见的问题 :wget未找到命令
  执行 yum -y install wget  

3. 安装mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装完这个包后,会获得两个mysql的yum repo源:
/etc/yum.repos.d/mysql-community.repo,
/etc/yum.repos.d/mysql-community-source.repo
查看可用的 mysql 安装文件
 yum repolist all | grep mysql 

4. 安装mysql

yum install mysql-server -y 

(1) 检查mysql是否安装成功

rpm -qa | grep mysql

在这里插入图片描述

(2) 执行mysql服务

#启动 mysql
systemctl start mysqld.service

#重启 mysql
systemctl restart mysqld.service 

#停止 mysql
systemctl stop mysqld.service 

#设置 mysql 开机启动
systemctl enable mysqld.service 
mysql常用文件路径:

/etc/my.cnf   这是mysql的主配置文件

/var/lib/mysql   mysql数据库的数据库文件存放位置

/var/logs/mysqld.log  数据库的日志输出存放位置

(3) 进入mysql

重启mysql后,执行
[root@localhost ~]# mysql -uroot -p 
Enter password: (回车进入mysql)(第一次安装没有密码)

(4) 修改mysql的密码

首先,密码不能过于简单,因为mysql默认对密码有复杂度要求。
可以通过下面命令关闭复杂度要求
mysql> set global validate_password_policy=0;       # 关闭密码复杂性策略
mysql> set global validate_password_length=4;      # 设置密码最低长度为4

然后进行密码重置

[root@localhost ~]# mysql_secure_installation
//
[root@localhost ~]# mysql_secure_installation



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y                       (设置密码)
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                     [是否删除匿名用户]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n               [是否禁止root远程登录]
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n       [是否删除test数据库]
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y                 [刷新权限]
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

5.授权远程登录

(1)登录mysql数据库

   mysql -u root -p

(2)授权登录

登录mysql之后执行
GRANT ALL PRIVILEGS ON . TO ‘ROOT’@’%’ IDENTIFIED BY ‘PASSWORD’ WITH GRANT OPTION;(注:此处的password指的是root用户的密码)
GRANT ALL PRIVILEGS ON . TO ‘ROOT’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;

(3)刷新mysql

 Mysql > flush  privileges;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力的小李

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值