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;
 
在CentOS 7上使用yum安装MySQL,你可以按照以下步骤进行操作: 1. 首先,你需要下载MySQLYum源配置文件。你可以使用以下命令从MySQL官网下载配置文件: ``` wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm ``` 2. 下载完成后,你可以使用以下命令将rpm包安装到系统中: ``` yum install mysql57-community-release-el7-9.noarch.rpm -y ``` 3. 安装完成后,你可以在`/etc/yum.repos.d/`目录下找到生成的两个repo文件:`mysql-community.repo`和`mysql-community-source.repo`。 4. 现在,你可以使用以下命令来查看可用的MySQL软件包: ``` yum repolist | grep mysql ``` 5. 确认系统信息,你可以使用以下命令来查询系统信息: ``` uname -a ``` 6. 根据查询到的系统信息,你可以从MySQL官网下载相应版本的Yum源配置文件。 7. 将下载的rpm包放到指定目录,例如`/usr/local/`目录下的`mysqldb`文件夹。 8. 最后,使用以下命令将Yum源配置文件添加到系统中: ``` yum install mysql80-community-release-el7-5.noarch.rpm -y ``` 这样,你就可以使用yum命令在CentOS 7上安装MySQL了。 #### 引用[.reference_title] - *1* *2* [centos7环境yum安装mysql](https://blog.csdn.net/hitits/article/details/107115240)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Centos7环境下yum方式安装MySQL](https://blog.csdn.net/m0_53166211/article/details/123121755)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值