1.在MySQL官网中下载YUM源rpm安装包
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2.安装下载的mysql源
yum localinstall mysql57-community-release-el7-11.noarch.rpm
3.检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
如下结果表示安装成功
mysql-connectors-community/x86_64 MySQL Connectors Community 45
mysql-tools-community/x86_64 MySQL Tools Community 59
mysql57-community/x86_64 MySQL 5.7 Community Server 247
4.安装mysql
yum install mysql-community-server
看到
Complete!
表示安装成功
5.启动mysql
systemctl start mysqld
6.查看mysql状态
systemctl status mysqld
如下,启动成功
Active: active (running) since Thu 2018-04-12 03:18:34 EDT; 5s ago
7.查看mysql默认为root生产的登录密码,在默认log文件中
grep 'temporary password' /var/log/mysqld.log
结果:
2018-04-12T07:18:27.547782Z 1 [Note] A temporary password is generated for root@localhost: ghAPa?);e4Df
root@localhost:后面就是密码(不包含前面的空格!)
8.使用默认生产的密码进行root用户登录
mysql -u root -p
提示:
Enter password:输入刚刚的密码
登录成功的话:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.21
Copyright (c) 2000, 2018, 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.
9.修改默认位root生产的密码
set password for 'root'@'localhost'=password('your密码')
注意:
mysql默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位
否则报错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
10.授权远程所有机器能用root用户和指定密码登录mysql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '指定密码' WITH GRANT OPTION;
使配置生效
FLUSH PRIVILEGES;
11.CentOs7使用firewalld做为防火墙策略,如果没开放3306端口,远程还是登录不了
开启3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
如果出现以下错误,表示防火墙未开启
FirewallD is not running
开启防火墙
systemctl start firewalld
查看防火墙状态,如下表示正在运行
systemctl status firewalld
Active: active (running) since Tue 2019-08-13 11:05:51 CST; 8s ago
重启firewalld防火墙,使生效
systemctl restart firewalld.service
等1到两分钟,远程就能链接了!
12.查看mysql版本号:
sql语句为:
select version();