centos7 yum安装mysql

此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:

grep "password" /var/log/mysqld.log
2020-06-06T14:10:51.115839Z 1 [Note] A temporary password is generated for root@localhost: Ikp,64lt9e:H
2020-06-06T14:15:53.791067Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)

  如下命令进入数据库:

[root@localhost ~]#  mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.30

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

 MySQL默认必须修改密码之后才能操作数据库,下面改密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

 

 这里有个问题,新密码设置的时候如果设置的过于简单会报错:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

  原因是因为MySQL有密码设置的规范,具体是与validate_password_policy的值有关:

 

  初始情况下validate_password_length是8。可以通过如下命令修改:

mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

  设置之后就是我上面查出来的那几个值了,此时密码就可以设置的很简单,例如1234之类的。到此数据库的密码设置就完成了。

  但此时还有一个问题,就是因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:

yum -y remove mysql57-community-release-el7-10.noarch
[root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-10 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                                     Arch                     Version                     Repository                   Size
====================================================================================================================================
Removing:
 mysql57-community-release                   noarch                   el7-10                      installed                    30 k

Transaction Summary
====================================================================================================================================
Remove  1 Package

Installed size: 30 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : mysql57-community-release-el7-10.noarch                                                                          1/1 
  Verifying  : mysql57-community-release-el7-10.noarch                                                                          1/1 

Removed:
  mysql57-community-release.noarch 0:el7-10                                                                                         

Complete!
[root@localhost ~]#

 

开启mysql的远程访问

执行以下命令开启远程访问限制(注意:下面命令开启的IP是 192.168.249.200,如要开启所有的,用%代替IP):

grant all privileges on *.* to 'root'@'192.168.249.200' identified by 'password' with grant option;
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;

 

注:password--是你设置你的mysql远程登录密码。

然后再输入下面命令使生效

mysql> flush privileges;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值