98300

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz

CentOS7系统中安装mysql5.7

[复制链接]
发表于 2020-5-12 13:46:18 | 显示全部楼层 |阅读模式
1、安装yum Repo
下载yum repo
  1. wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
复制代码
安装yum repo源
  1. yum localinstall mysql80-community-release-el7-3.noarch.rpm
复制代码
2、安装mysql57
  1. yum install mysql-community-server -y
复制代码
3、启动mysql
  1. systemctl start mysqld
复制代码
4、查看启动状态
  1. systemctl status mysqld
复制代码
可以看到如下
  1. [root@localhost ~]# systemctl status mysqld
  2. ● mysqld.service - MySQL Server
  3.    Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
  4.    Active: active (running) since Tue 2020-05-12 13:34:01 CST; 27s ago
  5.      Docs: man:mysqld(8)
  6.            http://dev.mysql.com/doc/refman/en/using-systemd.html
  7.   Process: 1311 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  8.   Process: 1262 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
  9. Main PID: 1314 (mysqld)
  10.    CGroup: /system.slice/mysqld.service
  11.            └─1314 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

  12. May 12 13:33:53 localhost.localdomain systemd[1]: Starting MySQL Server...
  13. May 12 13:34:01 localhost.localdomain systemd[1]: Started MySQL Server.
复制代码
说明mysql已经启动
5、查看mysql默认自动生成的密码
  1. grep 'temporary password' /var/log/mysqld.log
复制代码
或者直接查看/var/log/mysqld.log的密码
  1. [root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
  2. 2020-05-12T05:33:57.356832Z 1 [Note] A temporary password is generated for root@localhost: ToSpY_nw>1Op
复制代码
6、修改mysql数据库密码
  1. [root@localhost ~]# mysql -uroot -p
复制代码
输入上面的密码即可进入mysql数据库(MyNewPass123!要改为自己的密码)
  1. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass123!';
复制代码
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误。
修改完密码后,记得刷新一下
  1. FLUSH PRIVILEGES;
复制代码
7、开启远程登录
连接服务器: mysql -u root -p
  1. mysql -u root -p
复制代码

看当前所有数据库:show databases;
  1. show databases;
复制代码

进入mysql数据库:use mysql;
  1. use mysql;
复制代码

查看mysql数据库中所有的表:show tables;
  1. show tables;
复制代码

查看user表中的数据:select Host, User,Password from user;
  1. select Host, User,Password from user;
复制代码

修改user表中的Host:   update user set Host='%' where User='root';  
  1. update user set Host='%' where User='root';  
复制代码

说明: % 代表任意的客户端,可替换成具体IP地址。
最后刷新一下:flush privileges;
  1. flush privileges;
复制代码
8、设置mysql开机启动
  1. systemctl enable mysqld
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


QQ|Archiver|手机版|小黑屋|98300.NET

GMT+8, 2020-5-26 12:31 , Processed in 0.126710 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表