1. 下载mysql的repo源

CentOS 7.2的yum源中默认没有mysql,要先下载mysql的repo源

wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

2. 安装mysql57-community-release-el7-8.noarch.rpm包

rpm -ivh mysql57-community-release-el7-.noarch.rpm  --nodeps --force

3.安装mysql

yum install mysql-server

4. 启动mysql服务

查看MySQL服务是否已启动

service mysqld status

启动服务

systemctl start mysqld

对应的stop、restart等

5. 重置root密码

MySQL5.7会在安装后为root用户生成一个随机密码,而不是像以往版本的空密码。 
可以安全模式修改root登录密码或者用随机密码登录修改密码。下面用随机密码方式

MySQL为root用户生成的随机密码通过mysqld.log文件可以查找到:

grep 'temporary password' /var/log/mysqld.log

修改root用户密码:(MySQL的密码策略比较复杂,过于简单的密码会被拒绝)

mysql -u root -p
mysql> Enter password: (输入刚才查询到的随机密码)
mysql> SET PASSWORD FOR 'root'@'localhost'= "Root-123";
mysql> exit

用root新密码登录:

mysql -u root -pRoot-

住:如果上面的方式不能修改可以使用下面安全模式修改root:

关闭服务
systemctl stop mysqld.service
vi /etc/my.cnf
mysqld下面添加skip-grant-tables 保存退出启动服务
systemctl start mysqld.service
mysql -u root 不用密码直接回车
use mysql
update user set authentication_string=password('Root-123') where User='root' and Host='localhost';
flush privileges;
exit;
vi /etc/my.cnf 把 skip-grant-tables 一句删除保存退出重启mysql服务
systemctl restart mysqld.service
再次登录即可
mysql -u root -pRoot- 如果进行操作出现下面的提示:
You must reset your password using ALTER USER statement before executing this statement.
就再设置一遍密码
set password = password('Root-123');

6. 开放3306端口

允许使用用户名root密码Root-123456从任何主机连接到mysql服务器

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root-123456' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
mysql>exit;

开启防火墙mysql 3306端口的外部访问

firewall-cmd --zone=public --add-port=/tcp --permanent
firewall-cmd --reload

原文地址:http://blog.csdn.net/lochy/article/details/51721319

最新文章

  1. springmvc和struts2的区别
  2. 利用freemarker 静态化网页
  3. 找不到 com.google.zxing.ResultMetadataType 异常解决
  4. localstorage 使用
  5. 安装freebsd9 出现 mountroot>怎么办
  6. ubuntu中安装Docker
  7. 修改Hosts不生效的一个场景-web(转)
  8. linux下如何使用USB存储设备
  9. Java 7 JVM和垃圾收集
  10. kali权限提升之本地提权
  11. 如何在VB.net中建立word文档
  12. c++数字和字符串的转换
  13. Python中的logging模块【转】https://www.cnblogs.com/yelin/p/6600325.html
  14. 【shell编程】2、语法
  15. UDP网络程序,客户端和服务端交互原理
  16. JavaScript 编码规范(中文/Airbnb公司版)
  17. 20165228 2017-2018-2《Java程序设计》课程总结
  18. springweb flux 编程模型
  19. nexus 增加代理仓库 无法搜到snapshot的jar包 解决方法
  20. 6 scrapy框架之分布式操作

热门文章

  1. redis 服务相关
  2. 使用Data URL将图片嵌入到网页中
  3. Zookeeper的结构和命令
  4. JS实现背景图按时切换或者每次更新
  5. mysql—触发器trigger
  6. Android--推断文本文件编码
  7. android发送邮件
  8. java.lang.NoSuchMethodException: <init> [class android.content.Context, interface androidutil.Attri
  9. java中的字符集和编码
  10. 修改yum源为阿里云的