1、下载mysql安装包,
https://dev.mysql.com/downloads/mysql/
2、解压
我是放在了/usr/local目录下
tar -xvf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar /usr/local/
3、依次安装
mysql-community-common-8.0.19-1.el7.x86_64.rpm
mysql-community-libs-8.0.19-1.el7.x86_64.rpm
mysql-community-client-8.0.19-1.el7.x86_64.rpm
mysql-community-server-8.0.19-1.el7.x86_64.rpm
rpm -qa|grep -i mysql
rpm -ivh mysql-community-common-8.0.19-1.el7.x86_64.rpm
warning: mysql-community-common-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-8.0.19-1.e################################# [100%]
# rpm -ivh mysql-community-libs-8.0.19-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mariadb-libs is obsoleted by mysql-community-libs-8.0.19-1.el7.x86_64
这个报依赖错误,需要清除所有mysql依赖包
先查看这个依赖,再清除
# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
#yum remove mariadb-libs-5.5.60-1.el7_5.x86_64
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-7.el7 will be erased
--> Processing Dependency: /usr/sbin/sendmail for package: redhat-lsb-core-4.1-27.el7.centos.1.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Removing:
mariadb-libs x86_64 1:5.5.60-1.el7_5 @anaconda 4.4 M
Removing for dependencies:
postfix x86_64 2:2.10.1-7.el7 @anaconda 12 M
redhat-lsb-core x86_64 4.1-27.el7.centos.1 @base 45 k
Transaction Summary
=======================================================================================================
Remove 1 Package (+2 Dependent packages)
Installed size: 17 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Erasing : redhat-lsb-core-4.1-27.el7.centos.1.x86_64 1/3
Erasing : 2:postfix-2.10.1-7.el7.x86_64 2/3
Erasing : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 3/3
Verifying : redhat-lsb-core-4.1-27.el7.centos.1.x86_64 1/3
Verifying : 2:postfix-2.10.1-7.el7.x86_64 2/3
Verifying : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 3/3
Removed:
mariadb-libs.x86_64 1:5.5.60-1.el7_5
Dependency Removed:
postfix.x86_64 2:2.10.1-7.el7 redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1
Complete!
清除完了查看没有此依赖,继续安装
# rpm -qa|grep mariadb
# rpm -ivh mysql-community-libs-8.0.19-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-8.0.19-1.el7################################# [100%]
[root@iZ2ze6wftv0plydh6zw217Z mysql]# rpm -ivh mysql-community-client-8.0.19-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-8.0.19-1.e################################# [100%]
# rpm -ivh mysql-community-server-8.0.19-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.19-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-8.0.19-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.19-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.19-1.el7.x86_64
MySQL依赖libaio,所以先要安装libaio,我们通过 rpm -qa|grep libaio 命令查看一下,没有的话安装此依赖,然后再安装server 成功
# rpm -qa|grep libaio
# yum -y install libaio
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/3): epel/x86_64/group_gz | 95 kB 00:00:00
(2/3): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(3/3): epel/x86_64/primary_db | 6.8 MB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Installing:
libaio x86_64 0.3.109-13.el7 base 24 k
Transaction Summary
=======================================================================================================
Install 1 Package
Total download size: 24 k
Installed size: 38 k
Downloading packages:
libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : libaio-0.3.109-13.el7.x86_64 1/1
Verifying : libaio-0.3.109-13.el7.x86_64 1/1
Installed:
libaio.x86_64 0:0.3.109-13.el7
Complete!
# rpm -ivh mysql-community-server-8.0.19-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-8.0.19-1.e################################# [100%]
到此安装完成
4、启动mysql
systemctl start mysqld.service 启动mysql
systemctl status mysqld.service 查看mysql状态
5、登录mysql
首先查找临时密码
cat /var/log/mysqld.log |grep password
2020-04-17T06:07:25.679527Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost:UIjGhtWdt7+R
用如下命令登录
mysql -u root -p
Enter password:
登录后必须先修改密码才能执行任何操作
可以修改下用户密码
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password for root@localhost=password('123456');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'password('123456')' at line 1
mysql> alter user root@localhost identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
密码必须符合密码规范,可以设置一下不强制密码规范
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=6;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user root@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
退出mysql,重新用新密码登录
mysql> exit