-
下载安装包
官方下载网址
点击
Download
下载mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar
-
点击
No thanks, just start my download
直接下载也可以在
Centos7
用wget
直接下载[root@Centos ~]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar
[root@Centos ~]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar --2021-04-29 18:03:19-- https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar Resolving cdn.mysql.com (cdn.mysql.com)... 23.204.250.61 Connecting to cdn.mysql.com (cdn.mysql.com)|23.204.250.61|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 793600000 (757M) [application/x-tar] Saving to: ‘mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar’ 100%[==========================================================================================================>] 793,600,000 7.66MB/s in 1m 47s 2021-04-29 18:05:06 (7.09 MB/s) - ‘mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar’ saved [793600000/793600000]
-
把下载好的
mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar
上传至服务器 -
通过
rpm -qa | grep mariadb
命令查看mariadb
的安装包 -
通过
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps
命令装卸mariadb
[root@Centos ~]# rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps
-
通过
rpm -qa | grep mariadb
命令再次查看mariadb
的安装包 -
在
/usr/local
目录创建mysql
目录[root@Centos local]# mkdir mysql
-
mysql
安装包移到新创建的/usr/local/mysql
目录[root@Centos ~]# ls mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar [root@Centos ~]# mv mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar /usr/local/mysql/
-
通过
ls
命令查看一下/usr/local/mysql
[root@Centos mysql]# ls mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar #已经完成移动
-
通过
tar
命令解压tar
包[root@Centos mysql]# tar -xvf mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar
-
通过
ls
命令查看解压的结果[root@Centos mysql]# ls mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar mysql-community-embedded-compat-8.0.24-1.el7.x86_64.rpm mysql-community-client-8.0.24-1.el7.x86_64.rpm mysql-community-libs-8.0.24-1.el7.x86_64.rpm mysql-community-client-plugins-8.0.24-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.24-1.el7.x86_64.rpm mysql-community-common-8.0.24-1.el7.x86_64.rpm mysql-community-server-8.0.24-1.el7.x86_64.rpm mysql-community-devel-8.0.24-1.el7.x86_64.rpm mysql-community-test-8.0.24-1.el7.x86_64.rpm #接下来开始正式安装
-
通过
rpm -ivh mysql-community-common-8.0.24-1.el7.x86_64.rpm --nodeps --force
命令安装common
][root@Centos mysql]# rpm -ivh mysql-community-common-8.0.24-1.el7.x86_64.rpm --nodeps --force warning: mysql-community-common-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-common-8.0.24-1.e################################# [100%]
-
通过
rpm -ivh mysql-community-libs-8.0.24-1.el7.x86_64.rpm --nodeps --force
命令安装libs
[root@Centos mysql]# rpm -ivh mysql-community-libs-8.0.24-1.el7.x86_64.rpm --nodeps --force warning: mysql-community-libs-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-8.0.24-1.el7################################# [100%]
-
通过
rpm -ivh mysql-community-client-8.0.24-1.el7.x86_64.rpm --nodeps --force
命令安装client
[root@Centos mysql]# rpm -ivh mysql-community-client-8.0.24-1.el7.x86_64.rpm --nodeps --force warning: mysql-community-client-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-client-8.0.24-1.e################################# [100%]
-
通过
rpm -ivh mysql-community-server-8.0.24-1.el7.x86_64.rpm --nodeps --force
命令安装server
[root@Centos mysql]# rpm -ivh mysql-community-common-8.0.24-1.el7.x86_64.rpm --nodeps --force warning: mysql-community-common-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-common-8.0.24-1.e################################# [100%] [root@iZwz91gi0pal3t5041g3foZ mysql]# rpm -ivh mysql-community-libs-8.0.24-1.el7.x86_64.rpm --nodeps --force warning: mysql-community-libs-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-8.0.24-1.el7################################# [100%] [root@iZwz91gi0pal3t5041g3foZ mysql]# rpm -ivh mysql-community-client-8.0.24-1.el7.x86_64.rpm --nodeps --force warning: mysql-community-client-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-client-8.0.24-1.e################################# [100%] [root@iZwz91gi0pal3t5041g3foZ mysql]# rpm -ivh mysql-community-server-8.0.24-1.el7.x86_64.rpm warning: mysql-community-server-8.0.24-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.24-1.el7.x86_64 libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.24-1.el7.x86_64 libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.24-1.el7.x86_64 [root@iZwz91gi0pal3t5041g3foZ mysql]# rpm -ivh mysql-community-server-8.0.24-1.el7.x86_64.rpm --nodeps --force warning: mysql-community-server-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-server-8.0.24-1.e################################# [100%]
-
通过
rpm -qa | grep mysql
查看mysql
安装包[root@Centos mysql]# rpm -qa | grep mysql mysql-community-libs-8.0.24-1.el7.x86_64 mysql-community-server-8.0.24-1.el7.x86_64 mysql-community-common-8.0.24-1.el7.x86_64 mysql-community-client-8.0.24-1.el7.x86_64
-
通过以下命令,完成对
mysql
数据库的初始化和相关配置[root@Centos mysql]# mysqld --initialize [root@Centos mysql]# chown mysql:mysql /usr/local/mysql -R [root@Centos mysql]# systemctl start mysqld.service [root@Centos mysql]# systemctl enable mysqld
如果执行
mysqld --initialize
的时候报错,就需要安装libaio[root@Centos mysql]# mysqld --initialize mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决方式:
[root@Centos mysql]# yum install -y libaio
如果提示日志提示:
[ERROR] [MY-012271] [InnoDB] The innodb_system data file 'ibdata1' must be writable
解决方式:设置权限
[root@Centos mysql]# find / -name ibdata1 /var/lib/mysql/ibdata1 [root@Centos mysql]# chmod -R 777 /var/lib/mysql
通过
cat /var/log/mysqld.log | grep password
命令查看数据库的密码
-
通过
mysql -uroot -p
敲回车键进入数据库登陆界面[root@Centos mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.24 Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
-
通过
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'
命令来修改密码mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; Query OK, 0 rows affected (0.01 sec) mysql> exit;
在此修改密码为123456为例,根据自身实际情况设置密码
-
通过 exit; 命令退出 MySQL,然后通过新密码再次登陆
mysql> exit; Bye [root@Centos mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.24 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
-
通过以下命令,进行远程访问的授权
create user 'root'@'%' identified with mysql_native_password by '123456'; grant all privileges on *.* to 'root'@'%' with grant option; flush privileges;
mysql> create user 'root'@'%' identified with mysql_native_password by '123456'; Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to 'root'@'%' with grant option; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
-
通过
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
命令修改加密规则,MySql8.0 版本 和 5.0 的加密规则不一样,而现在的可视化工具只支持旧的加密方式。mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.01 sec)
-
通过 flush privileges; 命令刷新修该后的权限
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
-
通过
exit;
命令退出 MySQLmysql> exit; Bye
自此就可以用Navicat链接数据库,如果链接不成功就看一下检查防火墙。
这里用ssh登录到服务器再转到MySQL的方式登录数据库:
点击
测试连接
看是否成功: