安装 MySQL Repository 1、默认 yum 存储库安装
[root@qfedu.com ~]# yum -y install wget # 安装 wget下载工具 [root@qfedu.com ~]# wget https://repo.mysql.com/mysql57-community-release-el7- 11.noarch.rpm # 下载 mysql 官方 yum 源安装包 [root@qfedu.com ~]# 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)列出所有版本
[root@qfedu.com ~]# yum repolist all | grep mysql 发现启用最新8.0版本是 enabled 的,5.7版本是 disabled 的,需要安装5.7版本时,所以把8.0的进行禁用,然后再启用5.7版本
2)安装 yum 配置工具
[root@qfedu.com ~]# yum -y install yum-utils 3)禁用 8.0 版本
[root@qfedu.com ~]# yum-config-manager --disable mysql80-community 4)启用 5.7 版本
[root@qfedu.com ~]# yum-config-manager --enable mysql57-community 5)检查启用版本
注意:进行安装时请确保只有一个版本启用,否则会显示版本冲突
[root@qfedu.com ~]# yum repolist enabled | grep mysql 安装 MySQL 需要安装MySQL Server, MySQL client 已经包括在 server 套件内
[root@qfedu.com ~]# yum -y install mysql-community-server mysql # 安装服务 端,客户端 [root@qfedu.com ~]# systemctl start mysqld # 启动 mysql 服务 [root@qfedu.com ~]# systemctl enable mysqld # 设置 mysql 服务开机启动 [root@qfedu.com ~]# ls /var/lib/mysql # 查看 mysql 安装 [root@qfedu.com ~]# grep ‘tqfeduorary password’ /var/log/mysqld.log # 获取首次登 录密码 [root@qfedu.com ~]# mysql -uroot -p’awm3>!QFl6zR’ # 登录mysql 数据库 mysql > alter user ‘root’@‘localhost’ identified by ‘Qf.123com’; # 修改 mysql 数据库密码(密码必须符合复杂性要求,包含字母大小写,数字,特赦符号,长度不少于8位) [root@qfedu.com ~]# mysql -uroot -p’Qf.123com’ # 用新密码登 录数据库 重启 MySQL [root@qfedu.com ~]# systemctl restart mysqld 创建 qfedu 库并设置权限 [root@qfedu.com ~]# 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 ? 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 | ±------------------------------------------------------------------------------ ------------------------------+ | 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 qfedu@172.16.0.122 | ±------------------------------------------------------------------------------ ---------------------------------+ | 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
|