【CentOS7】:使用yum命令安装MySQL(只是为了后来少走弯路)

使用yum命令下载安装MySQL

CentOS7默认有一个Mariadb(这是MySQL的分支),使用命令安装会覆盖Mariadb

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

开始安装MySQL客户端

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

会花费一些时间,具体时间根据网速决定的

数据库配置

启动数据库

* 启动数据命令
[root@localhost ~]# systemctl start  mysqld.service
* 查看数据运行状态
[root@localhost ~]# systemctl status mysqld.service

从日志中找到数据库密码(随记生成)

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

登录数据库

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

修改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

其中‘new password’替换成你要设置的密码,注意:密码设置必须要大小写字母数字和特殊符号(,/’;:等),不然不能配置成功。
否则会如下错误

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

如果要修改成简单密码,则需要先设置,密码复杂度、长度等

* 修改设置密码长度
set global validate_password_length=6;
* 设置密码复杂度
set global validate_password_policy=LOW;
* 查看修改结果
SHOW VARIABLES LIKE 'validate_password%';

查询修改结果,如果没有修改密码,而输入这个密码则会报如下错误:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

开启MySQL的远程访问

  • 执行以下命令开启远程访问限制(注意:下面命令开启的IP是 192.168.19.128,如要开启所有的,用%代替IP):
grant all privileges on *.* to 'root'@'ip地址' identified by 'password' with grant option;

password是你设置你的MySQL远程登录密码

  • 然后输入
mysql> flush privileges;
  • 开启防火墙
* 查看firewall的状态
firewall-cmd --state
* 开发3306端口
firewall-cmd --permanent -add-port=3306/tcp
* 查看防火墙开发的端口
firewall-cmd --permanent --list-ports
* 重启防火墙
firewall-cmd --reload 
  • 设置数据库语言
    • 登录mysql 输入status
      在这里插入图片描述
      • 使用exit密令退出mysql
      • 编写4个语句
* 编辑my.cnf
vim /etc/my.cnf
* 按i键进行编辑
* 输入语句
[client]
default-caracter-set=utf8
...
character-set-server=utf8
collation-server=utf8_general_ci
* 按ESC键后输入wq回车保存退出

在这里插入图片描述

参考资料

CentOS7安装MySQL完整版
开启防火墙

猜你喜欢

转载自blog.csdn.net/weixin_45511500/article/details/115528537