下载并安装MySQL官方的 Yum Repository
这里安装mysql-5.7
# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
# yum -y install mysql57-community-release-el7-10.noarch.rpm
# yum -y install mysql-community-server
网速不好的话下载安装过程较慢,要等待一段时间
[root@localhost ~]# yum install mysql-community-server --nogpgcheck
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* epel: mirrors.aliyun.com
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.nwsuaf.edu.cn
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql57-community | 2.5 kB 00:00:00
(1/3): mysql57-community/x86_64/primary_db | 144 kB 00:00:02
(2/3): mysql-connectors-community/x86_64/primary_db | 20 kB 00:00:05
(3/3): mysql-tools-community/x86_64/primary_db | 41 kB 00:00:05
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.22-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.22-1.el7 for package: mysql-community-server-5.7.22-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.22-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.22-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.22-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.22-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:5.7.22-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.22-1.el7 will be obsoleting
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================
Installing:
mysql-community-libs x86_64 5.7.22-1.el7 mysql57-community 2.1 M
replacing 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
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 5.7.22-1.el7 mysql57-community 165 M
Installing for dependencies:
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
Transaction Summary
===================================================================================================================================
Install 3 Packages (+2 Dependent packages)
Total download size: 193 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.22-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-5.7.22-1.el7.x86_64.rpm | 274 kB 00:00:01
(2/5): mysql-community-libs-5.7.22-1.el7.x86_64.rpm | 2.1 MB 00:00:02
(3/5): mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm | 2.0 MB 00:00:06
(4/5): mysql-community-client-5.7.22-1.el7.x86_64.rpm | 24 MB 00:01:56
(5/5): mysql-community-server-5.7.22-1.el7.x86_64.rpm | 165 MB 00:17:07
-----------------------------------------------------------------------------------------------------------------------------------
Total 191 kB/s | 193 MB 00:17:17
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql57-community-release-el7-10.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-5.7.22-1.el7.x86_64 1/6
Installing : mysql-community-libs-5.7.22-1.el7.x86_64 2/6
Installing : mysql-community-client-5.7.22-1.el7.x86_64 3/6
Installing : mysql-community-server-5.7.22-1.el7.x86_64 4/6
Installing : mysql-community-libs-compat-5.7.22-1.el7.x86_64 5/6
Erasing : 1:mariadb-libs-5.5.56-2.el7.x86_64 6/6
Verifying : mysql-community-libs-compat-5.7.22-1.el7.x86_64 1/6
Verifying : mysql-community-common-5.7.22-1.el7.x86_64 2/6
Verifying : mysql-community-server-5.7.22-1.el7.x86_64 3/6
Verifying : mysql-community-client-5.7.22-1.el7.x86_64 4/6
Verifying : mysql-community-libs-5.7.22-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: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
Dependency Installed:
mysql-community-client.x86_64 0:5.7.22-1.el7 mysql-community-common.x86_64 0:5.7.22-1.el7
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
至此已安装完毕
接下来启动mysql
[root@localhost ~]# systemctl restart mysqld
启动成功之后进入mysql
通过# grep "password" /var/log/mysqld.log
查看初始密码
输入初始密码,此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password';
可能会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
提示是密码不安全过于简单
此时可通过执行
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
4、MySQL 8.0 调整密码验证规则:
mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=1;
修改mysql密码命名规则就可以设置1234这类密码了
但是出于安全性考虑,生产环境mysql不要执行此语句,设置一个安全性较强的密码。
可以通过mysql> SHOW VARIABLES LIKE 'validate_password%';
查看密码规则。
由于安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:
# yum -y remove mysql57-community-release-el7-10.noarch
创建远程连接用户
CREATE USER 'root'@'%' IDENTIFIED BY 'password';
#授权
grant all privileges on *.* to 'root'@'%';
flush privileges;