一、获取mysql的yum源rpm包
[root@localhost mnt]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
--2018-06-13 00:39:29-- http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm [跟随至新的 URL]
--2018-06-13 00:39:30-- https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm [跟随至新的 URL]
--2018-06-13 00:39:31-- https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 223.119.236.209
正在连接 repo.mysql.com (repo.mysql.com)|223.119.236.209|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9116 (8.9K) [application/x-redhat-package-manager]
正在保存至: “mysql57-community-release-el7-8.noarch.rpm”
100%[=============================================>] 9,116 --.-K/s 用时 0s
2018-06-13 00:39:31 (142 MB/s) - 已保存 “mysql57-community-release-el7-8.noarch.rpm” [9116/9116])
二、安装MySQL的yum源并检查yum源
[root@localhost mnt]# ll总用量 12
-rw-r--r--. 1 root root 9116 4月 11 2016 mysql57-community-release-el7-8.noarch.rpm
[root@localhost mnt]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
已加载插件:fastestmirror, langpacks
正在检查 mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch
mysql57-community-release-el7-8.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql57-community-release.noarch.0.el7-8 将被 安装
--> 解决依赖关系完成
base/7/x86_64 | 3.6 kB 00:00:00
base/7/x86_64/group_gz | 166 kB 00:00:01
base/7/x86_64/primary_db | 5.9 MB 00:00:59
extras/7/x86_64 | 3.4 kB 00:00:00
extras/7/x86_64/primary_db | 147 kB 00:00:00
updates/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 2.0 MB 00:00:01
依赖关系解决
=======================================================================================
Package 架构 版本 源 大小
=======================================================================================
正在安装:
mysql57-community-release noarch el7-8 /mysql57-community-release-el7-8.noarch 8.2 k
事务概要
=======================================================================================
安装 1 软件包
总计:8.2 k
安装大小:8.2 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql57-community-release-el7-8.noarch 1/1
验证中 : mysql57-community-release-el7-8.noarch 1/1
已安装:
mysql57-community-release.noarch 0:el7-8
完毕!
[root@localhost mnt]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 51
mysql-tools-community/x86_64 MySQL Tools Community 63
mysql57-community/x86_64 MySQL 5.7 Community Server 267
三、修改配置文件,选择自己想要安装的版本
[root@localhost mnt]# vim /etc/yum.repos.d/mysql-community.repo[mysql57-community]
name=MySQL 5.7 Community Serverbaseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.sohu.com
* extras: mirrors.163.com
* updates: mirrors.163.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.7.22-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 5.7.22-1.el7,它被软件包 mysql-community-server-5.7.22-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.7.9,它被软件包 mysql-community-server-5.7.22-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.7.22-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.7.9,它被软件包 mysql-community-client-5.7.22-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.5.7.22-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.56-2.el7 将被 取代
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
---> 软件包 mysql-community-libs.x86_64.0.5.7.22-1.el7 将被 舍弃
--> 正在检查事务
---> 软件包 mysql-community-libs-compat.x86_64.0.5.7.22-1.el7 将被 舍弃
--> 解决依赖关系完成
依赖关系解决
=======================================================================================
Package 架构 版本 源 大小
=======================================================================================
正在安装:
mysql-community-libs x86_64 5.7.22-1.el7 mysql57-community 2.1 M
替换 mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-libs-compat x86_64 5.7.22-1.el7 mysql57-community 2.0 M
替换 mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 5.7.22-1.el7 mysql57-community 165 M
为依赖而安装:
mysql-community-client x86_64 5.7.22-1.el7 mysql57-community 24 M
mysql-community-common x86_64 5.7.22-1.el7 mysql57-community 274 k
事务概要
=======================================================================================
安装 3 软件包 (+2 依赖软件包)
总下载量:193 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
mysql-community-common-5.7.22-1.el7.x86_64.rpm 的公钥尚未安装
(1/5): mysql-community-common-5.7.22-1.el7.x86_64.rpm | 274 kB 00:00:00
(2/5): mysql-community-libs-5.7.22-1.el7.x86_64.rpm | 2.1 MB 00:00:00
(3/5): mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm | 2.0 MB 00:00:15
(4/5): mysql-community-client-5.7.22-1.el7.x86_64.rpm | 24 MB 00:00:49
(5/5): mysql-community-server-5.7.22-1.el7.x86_64.rpm | 165 MB 00:17:23
---------------------------------------------------------------------------------------
总计 187 kB/s | 193 MB 17:39
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
导入 GPG key 0x5072E1F5:
用户ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
指纹 : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
软件包 : mysql57-community-release-el7-8.noarch (installed)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql-community-common-5.7.22-1.el7.x86_64 1/6
正在安装 : mysql-community-libs-5.7.22-1.el7.x86_64 2/6
正在安装 : mysql-community-client-5.7.22-1.el7.x86_64 3/6
正在安装 : mysql-community-server-5.7.22-1.el7.x86_64 4/6
正在安装 : mysql-community-libs-compat-5.7.22-1.el7.x86_64 5/6
正在删除 : 1:mariadb-libs-5.5.56-2.el7.x86_64 6/6
验证中 : mysql-community-libs-compat-5.7.22-1.el7.x86_64 1/6
验证中 : mysql-community-common-5.7.22-1.el7.x86_64 2/6
验证中 : mysql-community-server-5.7.22-1.el7.x86_64 3/6
验证中 : mysql-community-client-5.7.22-1.el7.x86_64 4/6
验证中 : mysql-community-libs-5.7.22-1.el7.x86_64 5/6
验证中 : 1:mariadb-libs-5.5.56-2.el7.x86_64 6/6
已安装:
mysql-community-libs.x86_64 0:5.7.22-1.el7
mysql-community-libs-compat.x86_64 0:5.7.22-1.el7
mysql-community-server.x86_64 0:5.7.22-1.el7
作为依赖被安装:
mysql-community-client.x86_64 0:5.7.22-1.el7
mysql-community-common.x86_64 0:5.7.22-1.el7
替代:
mariadb-libs.x86_64 1:5.5.56-2.el7
完毕!
[root@localhost mnt]#
[root@localhost mnt]# systemctl start mysqld
[root@localhost mnt]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2018-06-13 01:08:14 CST; 13s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4034 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 3950 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4037 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─4037 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid...
6月 13 01:07:43 localhost.localdomain systemd[1]: Starting MySQL Server...
6月 13 01:08:14 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost mnt]# systemctl enable mysqld
[root@localhost mnt]# systemctl daemon-reload
[root@localhost mnt]# grep 'temporary password' /var/log/mysqld.log
2018-06-12T17:08:08.511097Z 1 [Note] A temporary password is generated for root@localhost: ?-lal#-e1yjH
[root@localhost mnt]#
[root@localhost mnt]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22
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> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> show variables like '%password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyPASSWD!1';
Query OK, 0 rows affected (0.00 sec)
[root@localhost mnt]# vi /etc/my.cnf
#设置character-set-server=utf8
[root@localhost mnt]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.22 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> SHOW VARIABLES LIKE 'char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
mysql> exit
[root@localhost mnt]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 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> SHOW VARIABLES LIKE 'char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
mysql>
四、修改密码强度并修改密码
[root@localhost webapps]# mysql -u root -pEnter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 104405
Server version: 5.7.22 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> select @@validate_password_policy;
+----------------------------+
| @@validate_password_policy |
+----------------------------+
| MEDIUM |
+----------------------------+
1 row in set (0.03 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.73 sec)
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (1.49 sec)
mysql> set global validate_password_mixed_case_count=0;
Query OK, 0 rows affected (0.01 sec)
mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_special_char_count=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 3 |
| validate_password_mixed_case_count | 0 |
| validate_password_number_count | 3 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 0 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123');
Query OK, 0 rows affected, 1 warning (0.34 sec)
mysql>
五、配置MySQL用户远程登陆权限
mysql> show databases;+--------------------+
| Database |
+--------------------+
| information_schema |
| db_shebeimm_g |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set Host='%' where User='root';
Query OK, 1 row affected (0.15 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.05 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.16 sec)