操作系统:CentOS Linux release 7.3.1611 (Core)
参考:MySQL官方安装指南
直接安装官网指定noarch文件:
[root@localhost Downloads]# yum install https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm
检查源状态:
[root@localhost Downloads]# yum repolist all |grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 95
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 84
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 82
mysql80-community-source MySQL 8.0 Community Server - disabled
如果需要安装其他版本的mysql,可以使用yum-config-manager命令将不需要的源屏蔽,如要使用5.7的源则关闭8.0的源,开启5.7的源:
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
尝试安装mysql,报错:
[root@localhost Downloads]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.nju.edu.cn
* extras: mirrors.njupt.edu.cn
* updates: mirrors.nju.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.52-1.el7 will be obsoleted
--> Processing Dependency: mariadb-server for package: akonadi-mysql-1.9.2-4.el7.x86_64
---> Package mysql-community-server.x86_64 0:8.0.15-1.el7 will be obsoleting
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.15-1.el7 for package: mysql-community-server-8.0.15-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.0 for package: mysql-community-server-8.0.15-1.el7.x86_64
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be obsoleted
---> Package mariadb-server.x86_64 1:5.5.52-1.el7 will be updated
---> Package mariadb-server.x86_64 1:5.5.60-1.el7_5 will be an update
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.60-1.el7_5 for package: 1:mariadb-server-5.5.60-1.el7_5.x86_64
--> Processing Dependency: mariadb(x86-64) = 1:5.5.60-1.el7_5 for package: 1:mariadb-server-5.5.60-1.el7_5.x86_64
---> Package mysql-community-client.x86_64 0:8.0.15-1.el7 will be obsoleting
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.0 for package: mysql-community-client-8.0.15-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:8.0.15-1.el7 will be installed
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be updated
---> Package mariadb.x86_64 1:5.5.60-1.el7_5 will be an update
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be updated
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be an update
---> Package mysql-community-libs.x86_64 0:8.0.15-1.el7 will be obsoleting
---> Package mysql-community-libs-compat.x86_64 0:8.0.15-1.el7 will be obsoleting
Removing mariadb-libs.x86_64 1:5.5.60-1.el7_5 - u due to obsoletes from mysql-community-libs-compat.x86_64 0:8.0.15-1.el7 - u
Removing mariadb-server.x86_64 1:5.5.60-1.el7_5 - u due to obsoletes from mysql-community-server.x86_64 0:8.0.15-1.el7 - u
Removing mariadb.x86_64 1:5.5.60-1.el7_5 - u due to obsoletes from mysql-community-client.x86_64 0:8.0.15-1.el7 - u
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.60-1.el7_5 will be an update
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be an update
---> Package mariadb-server.x86_64 1:5.5.60-1.el7_5 will be an update
--> Processing Dependency: mariadb-server for package: akonadi-mysql-1.9.2-4.el7.x86_64
--> Finished Dependency Resolution
Error: Package: akonadi-mysql-1.9.2-4.el7.x86_64 (@anaconda)
Requires: mariadb-server
Removing: 1:mariadb-server-5.5.52-1.el7.x86_64 (@anaconda)
mariadb-server = 1:5.5.52-1.el7
Obsoleted By: mysql-community-server-8.0.15-1.el7.x86_64 (mysql80-community)
Not found
Updated By: 1:mariadb-server-5.5.60-1.el7_5.x86_64 (base)
mariadb-server = 1:5.5.60-1.el7_5
You could try using --skip-broken to work around the problem
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
ipa-client-4.4.0-12.el7.centos.x86_64 has installed conflicts freeipa-client: ipa-client-4.4.0-12.el7.centos.x86_64
ipa-client-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-client-common: ipa-client-common-4.4.0-12.el7.centos.noarch
ipa-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-common: ipa-common-4.4.0-12.el7.centos.noarch
错误显示系统中已默认安装了mariadb相关组件,检查rpm包:
[root@localhost Downloads]# rpm -qa | grep mysql*
[root@localhost Downloads]# rpm -qa | grep mariadb*
mariadb-server-5.5.52-1.el7.x86_64
mariadb-libs-5.5.52-1.el7.x86_64
mariadb-5.5.52-1.el7.x86_64
发现确实存在这些包,删除掉:
[root@localhost Downloads]# rpm -qa|grep mysql|xargs -i yum -y remove {}
[root@localhost Downloads]# rpm -qa|grep mariadb|xargs -i yum -y remove {}
再安装mysql:
[root@localhost Downloads]# yum install https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm
[root@localhost Downloads]# yum install mysql-community-server
执行成功后会安装:
mysql-community-server
mysql-community-client
mysql-community-common
mysql-community-libs
直接启动mysqld服务:
[root@localhost Downloads]# systemctl start mysqld.service
[root@localhost Downloads]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-02-26 15:58:28 CST; 25s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 32415 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 32487 (mysqld)
Status: "SERVER_OPERATING"
CGroup: /system.slice/mysqld.service
└─32487 /usr/sbin/mysqld
Feb 26 15:58:07 localhost.localdomain systemd[1]: Starting MySQL Server...
Feb 26 15:58:28 localhost.localdomain systemd[1]: Started MySQL Server.
查看原密码:
[root@localhost Downloads]# grep 'temporary password' /var/log/mysqld.log
2019-02-26T07:58:25.246382Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: W9*df,
使用密码登录mysql,并修改密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'oracle';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
密码修改受限,更改mysql配置后再次修改:
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'oracle';
Query OK, 0 rows affected (0.02 sec)
如此成功将密码修改为oracle