CentOS 7使用 MySQL Yum 存储库安装 MySQL5.7

1、卸载自带的MariaDB依赖包

[root@localhost ~]# yum makecache fast

[root@localhost ~]# yum list installed mariadb\*

 

[root@localhost ~]# yum remove mariadb-libs.x86_64

 

2、下载 MySQL 存储库

存储库页面 https://dev.mysql.com/downloads/repo/yum/

[root@localhost ~]# yum install wget -y

 

[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm

 

[root@localhost ~]# yum install mysql80-community-release-el7-7.noarch.rpm -y

[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"

 

[root@localhost ~]# yum repolist all | grep mysql

[root@localhost ~]# yum install -y yum-utils

 

关闭MySQL8.0的存储库配置

[root@localhost ~]# yum-config-manager --disable mysql80-community

 

开启MySQL5.7的存储库配置 

[root@localhost ~]# yum-config-manager --enable mysql57-community

[root@localhost ~]# yum repolist enabled | grep mysql

 

3、安装MySQL5.7

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

 

您可以使用 以下命令列出所有MySQL的软件包 MySQL Yum 中可用于您的平台的组件存储库:

[root@localhost ~]# yum --disablerepo=\* --enablerepo='mysql*-community*' list available

 

4、启动服务并且初始化数据库

[root@localhost ~]# service mysqld start

 

[root@localhost ~]# service mysqld status

 

 获取数据库的初始密码

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

初始化数据库

[root@localhost ~]# mysql_secure_installation

输入刚刚的密码 

[root@localhost ~]# mysql_secure_installation 

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : n

 ... 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? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

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

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
[root@localhost ~]# 

[root@localhost ~]# mysql_secure_installation

保护MySQL服务器部署。

输入root用户密码:

root用户密码已过期。处理步骤请设置新密码。

新密码:

重新输入新密码:

服务器上安装了'validate_password'插件。

后续步骤将使用现有配置运行

插件的。

使用已存在的root密码。

密码的估计强度:100

修改root用户密码?(按y| y表示是,其他键表示否):n

... 跳过。

默认情况下,MySQL安装有一个匿名用户,

允许任何人登录MySQL而不需要

为它们创建的用户帐户。这只是为了

测试,并使安装更加顺利。

您应该在进入生产环境之前删除它们

删除匿名用户?(按y| y表示“是”,其他键表示“否”):y

成功。

通常,应该只允许root用户从

“localhost”。这保证了有人不能猜到

来自网络的root密码。

禁止根用户远程登录?(按y| y表示“是”,其他键表示“否”):n

... 跳过。

默认情况下,MySQL附带一个名为“test”的数据库

任何人都可以访问。这也只用于测试,

并且应该在进入生产环境之前删除

环境。

删除测试数据库并访问它?(按y| y表示“是”,其他键表示“否”):y

-删除测试数据库…

成功。

-删除测试数据库的权限…

成功。

重新加载特权表将确保所有更改

目前所作的规定将立即生效。

现在重新加载特权表?(按y| y表示“是”,其他键表示“否”):y

成功。

全部完成!

root@localhost ~ #

大概英文解释如上,并且按提示输入y或者n

初始化数据库完成

默认密码策略 实施者要求 密码至少包含一个大写字母,一个 小写字母、一个数字和一个特殊字符,以及 密码总长度至少为 8 个字符。

重启数据库服务

[root@localhost ~]# service mysqld restart

[root@localhost ~]# service mysqld status

5、测试本地登录

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

 

注意:

Mysql默认是不区分大小写的,MySQL在Linux下数据库名、表名、列名、别名大小写规则是这样的
1)数据库名与表名是严格区分大小写的;
2)表的别名是严格区分大小写的;
3)列名与列的别名在所有的情况下均是忽略大小写的;
4)变量名也是严格区分大小写的; 

查看数据库版本

mysql> status;

 

退出MySQL

mysql> exit

 

6、远程登录开启并且测试(可选择开启远程或不开启远程) 

本地登录到数据库

查看数据库各个用户的访问权限

mysql> select user,host from mysql.user;

 

从上面我们可以观察到用户root的访问权限为localhost,表示root用户只支持本地访问

允许root远程
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '数据库root用户密码' WITH GRANT OPTION;
*.* 表示所有库的所有表,'root'用户,'%'表示远程'localhost'表示本地

mysql> grant all privileges on *.* to 'root'@'%' identified by 'xxx' with grant option;

 

刷新库表权限

mysql> flush privileges;

再次查看数据库各个用户的访问权限

mysql> select user,host from mysql.user;

 

测试远程登录

可以使用数据库连接工具也可以在另外一台安装了MySQL的服务器上使用命令连接

我这里选择后者

连接前要保证,被远程连接的MySQL服务器端要放行数据库端口

查看防火墙允许通过的服务

[root@localhost ~]# firewall-cmd --list-all

允许MySQL服务永久通过防火墙

[root@localhost ~]# firewall-cmd --permanent --add-service=mysql

 

重新加载firewalld规则

[root@localhost ~]# firewall-cmd --reload

 

数据库远程登录  mysql -h 数据库服务器主机地址 -P 数据库端口 -u 数据库用户 -p

[root@localhost ~]# mysql -h 10.0.0.4 -P 3306 -u root -p

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值