CentOS 7 安装 MySQL
下载MySQL Yum Repository
选择Archived版本
https://downloads.mysql.com/archives/community/
页面下载Repository
https://dev.mysql.com/downloads/repo/yum/
wget下载Repository
[root@centos ~]#wget -i -c http://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
[root@centos ~]# ll
-rw-r--r--. 1 root root 25820 Apr 18 13:24 mysql80-community-release-el7-1.noarch.rpm
下载repository可能遇到的问题
可能出现的错误
[root@centos ~]# wget -i -c http://dev.mysql.com/get/mysql80-community-release-el
--2018-01-01 00:26:03-- http://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm [following]
--2018-01-01 00:26:04-- https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
ERROR: cannot verify dev.mysql.com's certificate, issued by ‘/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA’:
Issued certificate not yet valid.
To connect to dev.mysql.com insecurely, use `--no-check-certificate'.
-c: No such file or directory
No URLs found in -c.
因为时间不准确
[root@centos ~]# date
Mon Jan 1 00:34:09 CST 2018
[root@centos ~]#
时间实际上是2019年
根据提示加入--no-check-certificate
wget --no-check-certificate -i -c https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
安装MySQL Yum Repository
[root@centos ~]# ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 1664 May 17 21:53 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 May 17 21:53 CentOS-CR.repo
-rw-r--r--. 1 root root 649 May 17 21:53 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 May 17 21:53 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 May 17 21:53 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 May 17 21:53 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 May 17 21:53 CentOS-Vault.repo
[root@centos ~]# yum install mysql80-community-release-el7-1.noarch.rpm
Loaded plugins: fastestmirror
Examining mysql80-community-release-el7-1.noarch.rpm: mysql80-community-release-el7-1.noarch
Marking mysql80-community-release-el7-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql80-community-release.noarch 0:el7-1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version
Repository Size
================================================================================
Installing:
mysql80-community-release
noarch el7-1 /mysql80-community-release-el7-1.noarch 31 k
Transaction Summary
================================================================================
Install 1 Package
Total size: 31 k
Installed size: 31 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql80-community-release-el7-1.noarch 1/1
Verifying : mysql80-community-release-el7-1.noarch 1/1
Installed:
mysql80-community-release.noarch 0:el7-1
Complete!
[root@centos ~]#
[root@centos ~]#
[root@centos ~]#
[root@centos ~]#
[root@centos ~]#
[root@centos ~]# ll /etc/yum.repos.d/
total 40
-rw-r--r--. 1 root root 1664 May 17 21:53 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 May 17 21:53 CentOS-CR.repo
-rw-r--r--. 1 root root 649 May 17 21:53 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 May 17 21:53 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 May 17 21:53 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 May 17 21:53 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 May 17 21:53 CentOS-Vault.repo
-rw-r--r--. 1 root root 1864 Feb 22 16:49 mysql-community.repo
-rw-r--r--. 1 root root 1885 Feb 22 16:49 mysql-community-source.repo
安装MySQL Server
[root@centos ~]# yum install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
mysql-connectors-community | 2.5 kB 00:00
mysql-tools-community | 2.5 kB 00:00
mysql80-community | 2.5 kB 00:00
(1/3): mysql-connectors-community/x86_64/primary_db | 24 kB 00:00
(2/3): mysql-tools-community/x86_64/primary_db | 45 kB 00:00
(3/3): mysql80-community/x86_64/primary_db | 26 kB 00:00
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.12-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.12-1.el7 for package: mysql-community-server-8.0.12-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.0 for package: mysql-community-server-8.0.12-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.12-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.0 for package: mysql-community-client-8.0.12-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:8.0.12-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:8.0.12-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:8.0.12-1.el7 will be obsoleting
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mysql-community-libs x86_64 8.0.12-1.el7 mysql80-community 2.2 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-libs-compat x86_64 8.0.12-1.el7 mysql80-community 2.1 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 8.0.12-1.el7 mysql80-community 349 M
Installing for dependencies:
mysql-community-client x86_64 8.0.12-1.el7 mysql80-community 26 M
mysql-community-common x86_64 8.0.12-1.el7 mysql80-community 541 k
Transaction Summary
================================================================================
Install 3 Packages (+2 Dependent packages)
Total download size: 379 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-common-8.0.12-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-8.0.12-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-8.0.12-1.el7.x86_64.rpm | 541 kB 00:01
(2/5): mysql-community-libs-8.0.12-1.el7.x86_64.rpm | 2.2 MB 00:02
(3/5): mysql-community-libs-compat-8.0.12-1.el7.x86_64.rpm | 2.1 MB 00:02
(4/5): mysql-community-client-8.0.12-1.el7.x86_64.rpm | 26 MB 00:16
(5/5): mysql-community-server-8.0.12-1.el7.x86_64.rpm | 349 MB 03:15
--------------------------------------------------------------------------------
Total 1.9 MB/s | 379 MB 03:21
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering "
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql80-community-release-el7-1.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-common-8.0.12-1.el7.x86_64 1/6
Installing : mysql-community-libs-8.0.12-1.el7.x86_64 2/6
Installing : mysql-community-client-8.0.12-1.el7.x86_64 3/6
Installing : mysql-community-server-8.0.12-1.el7.x86_64 4/6
Installing : mysql-community-libs-compat-8.0.12-1.el7.x86_64 5/6
Erasing : 1:mariadb-libs-5.5.56-2.el7.x86_64 6/6
Verifying : mysql-community-libs-8.0.12-1.el7.x86_64 1/6
Verifying : mysql-community-common-8.0.12-1.el7.x86_64 2/6
Verifying : mysql-community-server-8.0.12-1.el7.x86_64 3/6
Verifying : mysql-community-client-8.0.12-1.el7.x86_64 4/6
Verifying : mysql-community-libs-compat-8.0.12-1.el7.x86_64 5/6
Verifying : 1:mariadb-libs-5.5.56-2.el7.x86_64 6/6
Installed:
mysql-community-libs.x86_64 0:8.0.12-1.el7
mysql-community-libs-compat.x86_64 0:8.0.12-1.el7
mysql-community-server.x86_64 0:8.0.12-1.el7
Dependency Installed:
mysql-community-client.x86_64 0:8.0.12-1.el7
mysql-community-common.x86_64 0:8.0.12-1.el7
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
[root@centos ~]#
启动MySQL Server
启动MySQL Server
[root@centos ~]# systemctl start mysqld
开机启动MySQL Server
[root@centos ~]# systemctl enable mysqld
查看MySQL Server状态
[root@centos ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2018-07-28 15:12:53 CST; 28s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 24130 (mysqld)
Status: "SERVER_OPERATING"
CGroup: /system.slice/mysqld.service
└─24130 /usr/sbin/mysqld
Jul 28 15:12:33 centos systemd[1]: Starting MySQL Server...
Jul 28 15:12:53 centos systemd[1]: Started MySQL Server.
修改MySQL root用户密码
MySQL默认有一个root用户,并且有默认密码,密码保存在/var/log/mysqld.log文件中
这个root用户并不是Linux系统的用户
查看root默认密码
[root@centos ~]# grep 'temporary password' /var/log/mysqld.log
2018-07-28T07:12:39.615794Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 8P*k!ws,Od5n
[root@centos ~]#
修改root密码
[root@centos ~]# mysql -uroot -p
使用上面查询到的密码登录
Enter password:
mysql>
修改密码,默认的密码要求为:包含大写字母/小写字母、数字、特殊字符、最少8位
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
Query OK, 0 rows affected (0.06 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye
[root@centos ~]#
密码要求
如果密码不符合要求,会提示错误,并且设置的密码不会生效
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql>
查看密码要求
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| 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.15 sec)
修改密码规则
mysql>
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
参考资料