1、默认 yum 存储库安装 [[email protected] ~]# yum -y install wget # 安装 wget下载工具 [[email protected] ~]# wget https://repo.mysql.com/mysql57-community-release-el7- 11.noarch.rpm # 下载 mysql 官方 yum 源安装包 [[email protected] ~]# yum -y localinstall mysql57-community-release-el7- 11.noarch.rpm # 安装 mysql 官方 yum 源 2、选择指定发行版本安装 使用 MySQL Yum 存储库时,默认情况下会选择要安装的最新GA版本MySQL。默认启用最新GA 系列(当前为MySQL 8.0)的子存储库,而所有其他系列(例如,MySQL 5.7系列)的子存储库均 被禁用。查看已启用或禁用了存储库。 1、列出所有版本 [[email protected] ~]# yum repolist all | grep mysql 发现启用最新8.0版本是 enabled 的,5.7版本是 disabled 的,需要安装5.7版本时,所以把8.0的 进行禁用,然后再启用5.7版本 2、安装 yum 配置工具 [[email protected] ~]# yum -y install yum-utils 3、禁用 8.0 版本 [[email protected] ~]# yum-config-manager --disable mysql80-community 4、启用 5.7 版本 [[email protected] ~]# yum-config-manager --enable mysql57-community 5、检查启用版本 [[email protected] ~]# yum repolist enabled | grep mysql 2、安装 MySQL 需要安装MySQL Server, MySQL client 已经包括在 server 套件内 [[email protected] ~]# yum -y install mysql-community-server mysql # 安装服务 端,客户端 [[email protected] ~]# systemctl start mysqld # 启动 mysql 服务 [[email protected] ~]# systemctl enable mysqld # 设置 mysql 服务开机启动 [[email protected] ~]# ls /var/lib/mysql # 查看 mysql 安装 [[email protected] ~]# grep 'tqfeduorary password' /var/log/mysqld.log # 获取首次登 录密码 [[email protected] ~]# mysql -uroot -p'awm3>!QFl6zR' # 登录mysql 数据库 mysql > alter user 'root'@'localhost' identified by 'Qf.123com'; # 修改 mysql 数据库密码(密码必须符合复杂性要求,包含字母大小写,数字,特赦符号,长度不少于8位) [[email protected] ~]# mysql -uroot -p'Qf.123com' # 用新密码登 录数据库 3、重启 MySQL [[email protected] ~]# systemctl restart mysqld 4、创建 qfedu 库并设置权限 [[email protected] ~]# 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.6.39 MySQL Community Server (GPL) 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. mysql>CREATE DATABASE qfedudb CHARACTER SET utf8 COLLATE utf8_bin; Query OK, 1 row affected (0.00 sec) mysql>GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER,INDEX on qfedudb.* TO 'qfedu'@'localhost' IDENTIFIED BY 'Yangge.123com'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> SHOW GRANTS FOR 'qfedu'@'localhost'; +------------------------------------------------------------------------------- ------------------------------+ | Grants for qfedu@localhost | +------------------------------------------------------------------------------- ------------------------------+ 千锋教育云计算学院三、结构化查询语言 SQL 结构化查询语言(Structured Query Language),简称SQL,是数据库的标准查询语言。可以通过 DBMS对数据库进行定义数据,操纵数据,查询数据,数据控制等 1、数据定义语言 (DDL) Data Dafifinitaon Language 如创建表 create 删除表 drop 修改表 alter 清空表 truncate,彻底清空,无法找回 | GRANT USAGE ON *.* TO 'qfedu'@'localhost' IDENTIFIED BY PASSWORD '*841E9705B9F4BD3195B7314CA58A7E3B3B349F71' | | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `qfedudb`.* TO 'qfedu'@'localhost' | +------------------------------------------------------------------------------- ------------------------------+ 2 rows in set (0.00 sec) mysql> SHOW GRANTS FOR 'qfedu'@'172.16.0.122'; +------------------------------------------------------------------------------- ---------------------------------+ | Grants for [email protected] | +------------------------------------------------------------------------------- ---------------------------------+ | GRANT USAGE ON *.* TO 'qfedu'@'172.16.0.122' IDENTIFIED BY PASSWORD '*841E9705B9F4BD3195B7314CA58A7E3B3B349F71' | | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `qfedudb`.* TO 'qfedu'@'172.16.0.122' | +------------------------------------------------------------------------------- ---------------------------------+ 2 rows in set (0.01 sec) mysql> \q Bye
标签:安装,数据库,MySQL,qfedu,yum,mysql,root,com From: https://www.cnblogs.com/blueas/p/17401719.html