包含安装和简单的配置。

下载
本文下载的是:mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

1
2
3
tar -xvf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
```
释放如下 rpm 包:

[root@AndyCentOS7Basic forCentOS]# ll
total 1158730
-rwxrwx—. 1 root vboxsf 593274880 Nov 8 06:00 mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
-rwxrwx—. 1 root vboxsf 25090196 Nov 8 07:12 mysql-community-client-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 278300 Nov 8 07:12 mysql-community-common-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 3778120 Nov 8 07:11 mysql-community-devel-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 46238924 Nov 8 07:11 mysql-community-embedded-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 24077232 Nov 8 07:11 mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 128440800 Nov 8 07:12 mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 2238604 Nov 8 07:11 mysql-community-libs-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 2115892 Nov 8 07:11 mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 55538708 Nov 8 07:11 mysql-community-minimal-debuginfo-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 171597916 Nov 8 07:12 mysql-community-server-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 15256460 Nov 8 07:12 mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
-rwxrwx—. 1 root vboxsf 118609776 Nov 8 07:12 mysql-community-test-5.7.20-1.el7.x86_64.rpm

1
安装的时候,有顺序要求,同时,会与 mariadb 冲突,如下:

[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mysql-community-client(x86-64) >= 5.7.9 is needed by mysql-community-server-5.7.20-1.el7.x86_64
mysql-community-common(x86-64) = 5.7.20-1.el7 is needed by mysql-community-server-5.7.20-1.el7.x86_64
net-tools is needed by mysql-community-server-5.7.20-1.el7.x86_64
[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mysql-community-libs(x86-64) >= 5.7.9 is needed by mysql-community-client-5.7.20-1.el7.x86_64
[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.20-1.el7.x86_64
mariadb-libs is obsoleted by mysql-community-libs-5.7.20-1.el7.x86_64
[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing… ################################# [100%]

各种冲突 …

file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64

[root@AndyCentOS7Basic forCentOS]#

1
解决冲突,先卸载 mariadb 再操作

[root@AndyCentOS7Basic forCentOS]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@AndyCentOS7Basic forCentOS]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
[root@AndyCentOS7Basic forCentOS]# rpm -e postfix-2:2.10.1-6.el7.x86_64 postfix-2:2.10.1-6.el7.x86_64
[root@AndyCentOS7Basic forCentOS]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64
[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:mysql-community-common-5.7.20-1.e################################# [100%]
[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:mysql-community-libs-5.7.20-1.el7################################# [100%]
[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:mysql-community-client-5.7.20-1.e################################# [100%]
[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-devel-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-devel-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:mysql-community-devel-5.7.20-1.el################################# [100%]
[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
net-tools is needed by mysql-community-server-5.7.20-1.el7.x86_64
[root@AndyCentOS7Basic forCentOS]# yum install -y net-tools

Installed:
net-tools.x86_64 0:2.0-0.22.20131004git.el7

Complete!
[root@AndyCentOS7Basic forCentOS]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:mysql-community-server-5.7.20-1.e################################# [100%]
[root@AndyCentOS7Basic forCentOS]# rpm -qa | grep mysql
mysql-community-client-5.7.20-1.el7.x86_64
mysql-community-libs-5.7.20-1.el7.x86_64
mysql-community-devel-5.7.20-1.el7.x86_64
mysql-community-server-5.7.20-1.el7.x86_64
mysql-community-common-5.7.20-1.el7.x86_64

1
2
3
4
5
6
# 各项命令,与 CentOS 6 系列的 service mysqld start|restart|stop|status 不太一样。
启动 mysql 服务 : systemctl start mysqld
重启:systemctl restart mysqld
停止:systemctl stop mysqld
开机自启:systemctl enable mysqld
查看MySQL的启动状态:systemctl status mysqld

[root@AndyCentOS7Basic forCentOS]# systemctl start mysqld.service
[root@AndyCentOS7Basic forCentOS]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2017-11-08 09:28:22 CST; 6min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 14818 (mysqld)
CGroup: /system.slice/mysqld.service
└─14818 /usr/sbin/mysqld –daemonize –pid-file=/var/run/mysqld/mysqld.pid

[root@AndyCentOS7Basic forCentOS]# systemctl stop mysqld
[root@AndyCentOS7Basic forCentOS]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Wed 2017-11-08 09:38:47 CST; 8s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 14895 ExecStart=/usr/sbin/mysqld –daemonize –pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 14876 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 14897 (code=exited, status=0/SUCCESS)

Nov 08 09:38:21 AndyCentOS7Basic systemd[1]: Starting MySQL Server…
Nov 08 09:38:22 AndyCentOS7Basic systemd[1]: Started MySQL Server.
Nov 08 09:38:45 AndyCentOS7Basic systemd[1]: Stopping MySQL Server…
Nov 08 09:38:47 AndyCentOS7Basic systemd[1]: Stopped MySQL Server.
[root@AndyCentOS7Basic forCentOS]#

1
2
3
# 修改root本地登录密码
mysql 首次启动,在/var/log/mysqld.log 文件中给 root 生成了一个临时密码。
通过下面的方式找到 root 临时密码,然后登录 mysql 进行修改:

[root@AndyCentOS7Basic forCentOS]# grep ‘temporary password’ /var/log/mysqld.log
2017-11-08T01:28:17.646798Z 1 [Note] A temporary password is generated for root@localhost: #L+rRHgQs2Oz

1
登录并修改 root 密码:

[root@AndyCentOS7Basic forCentOS]# mysql -uroot -p#L+rRHgQs2Oz
mysql> ALTER USER ‘root‘@’localhost’ IDENTIFIED BY ‘mypassword’;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

1
2
mysql5.7 默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示 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 ‘mypassword’;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like ‘%password%’;
+—————————————+——–+
| Variable_name | Value |
+—————————————+——–+
| default_password_lifetime | 0 |
| disconnect_on_expired_password | ON |
| log_builtin_as_identified_by_password | OFF |
| mysql_native_password_proxy_users | OFF |
| old_passwords | 0 |
| report_password | |
| sha256_password_proxy_users | OFF |
| 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 |
+—————————————+——–+
14 rows in set (0.00 sec)

1
添加允许远程登录的账号,如果为 % 表示所有 IP,这里仅指定宿主主机的 IP

mysql> GRANT ALL PRIVILEGES ON . TO ‘admin‘@’192.168.1.89’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

1
2

# windows 10 客户端,解压版,需要安装 vc 运行时。否则报错:

The code execution cannot proceed because MSVCR120.dll was not found. Reinstalling the program may fix this problem.
The code execution cannot proceed because MSVCP120.dll was not found. Reinstalling the program may fix this problem.

1
2
3
4
[下载 Visual C++ Redistributable Packages for Visual Studio 2013](https://www.microsoft.com/en-US/download/details.aspx?id=40784)

# ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.88' (10060)
关闭防火墙,或者配置例外。这里是本地开发环境,直接关闭即可。

[root@AndyCentOS7Basic ~]# systemctl stop firewalld
[root@AndyCentOS7Basic ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 2018-02-03 安装最新版手记(实际安装步骤)
在阿里云上操作的。
[root@izwz97mqm1h3u2vxe4kesjz ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64

卸载 mariadb 之后,操作顺序如下:
rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm

# 华夏主机

[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
/usr/bin/perl is needed by mysql-community-server-5.7.21-1.el7.x86_64
perl(Getopt::Long) is needed by mysql-community-server-5.7.21-1.el7.x86_64
perl(strict) is needed by mysql-community-server-5.7.21-1.el7.x86_64

yum install -y perl

1
2

# 阿里云主机 CentOS 7.5 64 bit,安装 5.7.22

[root@hjweb01 mysql]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64

需要安装这依赖包

yum install -y libaio

Installed:
libaio.x86_64 0:0.3.109-13.el7
`
然后再执行 rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm 就可以了。