美文网首页linux
3.MySQL5.7在Centos7下安装步骤

3.MySQL5.7在Centos7下安装步骤

作者: 一枼落知天下 | 来源:发表于2019-05-31 20:32 被阅读102次

第一步:Cenos7之后都默认安装的是MariaDB,直接安装MySQL会出现冲突,所以先查找出已安装的MariaDB

rpm -qa | grep mariadb

第二步:删除旧版本mariadb

[root@ShuaiJhou ~]# yum -y remove mariadb*
[root@ShuaiJhou ~]# rpm -qa | grep mariadb
[root@ShuaiJhou ~]# 

nodeps代表强制,后面跟刚才查询出来的结果,移除之后可以再用上一条命令检验

rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

第三步:yum 安装MySQL 5.7的方法

1.下载MYSQL5.7包

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

2.再安装MYSQL源

[root@ShuaiJhou ~]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
[root@ShuaiJhou ~]# yum list

3.yum安装MYSQL

[root@ShuaiJhou ~]# yum -y install mysql-community-server
[root@ShuaiJhou ~]# systemctl start mysqld  #启动MySQL会生成临时密码

第四步:启动MySQL服务并设置开机自启动

[root@ShuaiJhou ~]# systemctl start mysqld
[root@ShuaiJhou ~]# systemctl enable mysqld

第五步:获取自动生成的MySQL密码,并进入MySQL

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

温馨提示:


第六步:进入必须先修改密码。否则什么都做不了。mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:

温馨提示: 如果想设置简单密码,如下操作:
方法一:首先,修改validate_password_policy参数的值
mysql> set global validate_password_policy=0;

Query OK, 0 rows affected (0.03 sec)
定义复杂度的级别:
0:只检查长度。
1:检查长度、数字、大小写、特殊字符。
2:检查长度、数字、大小写、特殊字符字典文件
mysql> set global validate_password_length=1; #定义长度 默认是8位数修改为1后密码长度>=4位数
Query OK, 0 rows affected (0.01 sec)

[root@ShuaiJhou ~]# mysql -uroot -p'k;tGXz>XF4AC'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26

Copyright (c) 2000, 2019, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY '123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_length=0;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1234';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1234';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1234789';
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';
Query OK, 0 rows affected (0.00 sec)

mysql> set password  for  root@localhost = password('123456'); 
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit
Bye
[root@ShuaiJhou ~]# mysql -uroot -p123456 
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> 

第七步:增加一个新用户用于navicat远程连接

mysql> GRANT ALL PRIVILEGES ON *.* TO 'zhoushuai'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION ;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> 

第八步:配置默认编码为utf8,进入/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

character_set_server=utf8
init_connect='SET NAMES utf8'

第九步:安装完成

第十步:阿里云放开3306端口



相关文章

网友评论

    本文标题:3.MySQL5.7在Centos7下安装步骤

    本文链接:https://www.haomeiwen.com/subject/lazgtctx.html