Java充电社
专辑
博文
联系我
本人继续续收门徒,亲手指导
Linux专题第21篇:Centos7安装MySQL8
相关专辑:
Linux专题
<div style="display:none"></div> ## 1)卸载本机mariadb > 先查看mariadb的安装包,然后卸载,最后可再次查看确认 ```shell [root@test001 mysql]# rpm -qa | grep mariadb mariadb-libs-5.5.68-1.el7.x86_64 [root@test001 mysql]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64 [root@test001 mysql]# rpm -qa | grep mariadb ``` ## 2)下载mysql(网盘、官网) **(1)网盘地址** ```shell 链接:https://pan.baidu.com/s/1_N830MgeYLt_VF4bTFWj2w 提取码:yyds ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/c1c22cc8-41b4-4511-ae78-b3b9174696a9.png) **(2)官网下载** > 根据自己的机子到MySQL官网下载对应的数据库https://dev.mysql.com/downloads/mysql/ ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/3048e614-1f13-40ab-ba5d-cdcfdbb45995.png) ## 3)下载完成 ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/7d92d253-44a4-4fda-b178-cb4d89ab02a6.png) ## 4)上传并解压 上传到`/opt/soft/mysql`目录 ```shell [root@test001 ~]# mkdir -p /opt/soft/mysql [root@test001 ~]# cd /opt/soft/mysql/ [root@test001 ~]# rz [root@test001 mysql]# ls mysql-8.0.29-1.el7.x86_64.rpm-bundle.tar [root@test001 mysql]# tar -xvf mysql-8.0.29-1.el7.x86_64.rpm-bundle.tar mysql-community-client-8.0.29-1.el7.x86_64.rpm mysql-community-client-plugins-8.0.29-1.el7.x86_64.rpm mysql-community-common-8.0.29-1.el7.x86_64.rpm mysql-community-debuginfo-8.0.29-1.el7.x86_64.rpm mysql-community-devel-8.0.29-1.el7.x86_64.rpm mysql-community-embedded-compat-8.0.29-1.el7.x86_64.rpm mysql-community-icu-data-files-8.0.29-1.el7.x86_64.rpm mysql-community-libs-8.0.29-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.29-1.el7.x86_64.rpm mysql-community-server-8.0.29-1.el7.x86_64.rpm mysql-community-server-debug-8.0.29-1.el7.x86_64.rpm mysql-community-test-8.0.29-1.el7.x86_64.rpm [root@test001 mysql]# ll 总用量 1609156 -rw-r--r--. 1 root root 823879680 5月 16 13:07 mysql-8.0.29-1.el7.x86_64.rpm-bundle.tar -rw-r--r--. 1 7155 31415 14668996 3月 24 19:43 mysql-community-client-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 2574424 3月 24 19:43 mysql-community-client-plugins-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 648680 3月 24 19:43 mysql-community-common-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 445936940 3月 24 19:44 mysql-community-debuginfo-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 1949700 3月 24 19:44 mysql-community-devel-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 4214948 3月 24 19:44 mysql-community-embedded-compat-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 2216040 3月 24 19:45 mysql-community-icu-data-files-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 1575404 3月 24 19:45 mysql-community-libs-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 683148 3月 24 19:45 mysql-community-libs-compat-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 55984868 3月 24 19:45 mysql-community-server-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 22960584 3月 24 19:46 mysql-community-server-debug-8.0.29-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 270450256 3月 24 19:47 mysql-community-test-8.0.29-1.el7.x86_64.rpm ``` ## 5)依次安装下面软件包,其余的可以不用管 > mysql-community-common > mysql-community-libs > mysql-community-client > mysql-community-server ```shell rpm -ivh --nodeps --force mysql-community-common-8.0.29-1.el7.x86_64.rpm rpm -ivh --nodeps --force mysql-community-libs-8.0.29-1.el7.x86_64.rpm rpm -ivh --nodeps --force mysql-community-client-8.0.29-1.el7.x86_64.rpm rpm -ivh --nodeps --force mysql-community-server-8.0.29-1.el7.x86_64.rpm ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/05309ec2-cdf2-421c-bc26-32a995650199.png) ## 6)查看已安装的mysql资源 > 我们安装了4个,所以列出来的也是4个 ```shell [root@test001 mysql]# rpm -qa | grep mysql mysql-community-server-8.0.29-1.el7.x86_64 mysql-community-common-8.0.29-1.el7.x86_64 mysql-community-libs-8.0.29-1.el7.x86_64 mysql-community-client-8.0.29-1.el7.x86_64 ``` ## 7)对mysql的初始化及相关配置 > 输入以下4条命令,完成对mysql的初始化及相关配置 ```shell [root@test001 mysql]# mysqld --initialize [root@test001 mysql]# chown -R mysql:mysql /var/lib/mysql [root@test001 mysql]# systemctl start mysqld.service [root@test001 mysql]# systemctl enable mysqld ``` ## 8)查看数据库的初始密码 ```shell cat /var/log/mysqld.log | grep password ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/8c03917a-282b-4eee-8006-b8ddcdb7e795.png) ## 9)使用root用户登录mysql,输入初始密码 ```shell mysql -u root -p ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/45858200-234b-4f35-81de-efa5e2179ca6.png) ## 10)修改root密码 ```shell alter user "root"@"localhost" identified by "1qaz@2wsx"; ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/1bdc184c-4f1e-4d7d-aeda-5026bfc05cb7.png) ## 11)通过以下命令,进行远程访问的授权 ```shell create user 'root'@'%' identified with mysql_native_password by '1qaz@2wsx'; grant all privileges on *.* to 'root'@'%' with grant option; flush privileges; --立即生效 ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/3b87ecaa-e457-4efb-a03d-66782271c578.png) ## 12)通过以下命令修改加密规则 > MySql8.0 版本 和 5.0 的加密规则不一样,而现在的可视化工具只支持旧的加密方式,最后刷新修改后的权限 ```sh ALTER USER 'root'@'localhost' IDENTIFIED BY '1qaz@2wsx' PASSWORD EXPIRE NEVER; flush privileges; ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/554269e5-b41d-486e-baa9-e51e3b3e592c.png) ## 13)关闭 firewall ```shell systemctl stop firewalld.service systemctl disable firewalld.service systemctl mask firewalld.service ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/0ccfb8ee-9ba0-4958-aa83-6ff39e251c01.png) ## 14)安装iptables防火墙 > 出现完成!或者Complete!即为成功,命令如下 ```shell yum -y install iptables-services ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/75d445ea-a18e-4267-b591-f46a37f97586.png) ## 15)启动设置防火墙 ```shell systemctl enable iptables; systemctl start iptables; systemctl status iptables; ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/6f69da6a-eac9-4b12-a55f-bc9b6e1f92f0.png) ## 16)对外开放mysql端口 通过vi /etc/sysconfig/iptables命令编辑防火墙 ```shell vi /etc/sysconfig/iptables ``` 在iptables中添加下面内容,位置如下图,不要放错地方了 ```shell -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/bbeac9c8-a034-4ed9-b054-da64a7e32c52.png) ## 17)重启防火墙,使配置生效 ```shell systemctl restart iptables.service ``` ## 18)通过命令设置防火墙开机启动 ``` systemctl enable iptables.service ``` ## 19)使用客户端工具连接测试即可 ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/77e0da50-5042-4f54-8074-a5008c6ffc53.png) ## 20)如何修改mysql端口?(/etc/my.cnf) mysql配置文件位置`/etc/my.cnf`,可以编辑这个文件修改mysql配置。 **(1)比如将端口修改为33307** > 编辑/etc/my.cnf文件,在[mysqld]下面添加`port=33307` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/49dc9765-8c92-431c-a8b3-ecf586117e82.png) **(2)执行下面命令,重启mysql服务** ```shell systemctl restart mysqld ``` **(3)对外开放33307端口** 通过下面命令编辑iptables ```shell vi /etc/sysconfig/iptables ``` 添加下面内容 ```shell -A INPUT -p tcp -m state --state NEW -m tcp --dport 33307 -j ACCEPT ``` ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/4e797e11-6896-44cb-8a12-c1aae27d00e1.png) **(4)执行下面命令,重启iptables服务** ```shell systemctl restart iptables ``` **(5)客户端连接测试** ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/288/118ed97b-6446-4a66-a78f-358b5e04b1bb.png) <a style="display:none" target="_blank" href="https://mp.weixin.qq.com/s/_S1DD2JADnXvpexxaBwLLg" style="color:red; font-size:20px; font-weight:bold">继续收门徒,亲手带,月薪 4W 以下的可以来找我</a> ## 最新资料 1. <a href="https://mp.weixin.qq.com/s?__biz=MzkzOTI3Nzc0Mg==&mid=2247484964&idx=2&sn=c81bce2f26015ee0f9632ddc6c67df03&scene=21#wechat_redirect" target="_blank">尚硅谷 Java 学科全套教程(总 207.77GB)</a> 2. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247484192&idx=1&sn=505f2faaa4cc911f553850667749bcbb&scene=21#wechat_redirect" target="_blank">2021 最新版 Java 微服务学习线路图 + 视频</a> 3. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247484573&idx=1&sn=7f3d83892186c16c57bc0b99f03f1ffd&scene=21#wechat_redirect" target="_blank">阿里技术大佬整理的《Spring 学习笔记.pdf》</a> 4. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247484544&idx=2&sn=c1dfe907cfaa5b9ae8e66fc247ccbe84&scene=21#wechat_redirect" target="_blank">阿里大佬的《MySQL 学习笔记高清.pdf》</a> 5. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247485167&idx=1&sn=48d75c8e93e748235a3547f34921dfb7&scene=21#wechat_redirect" target="_blank">2021 版 java 高并发常见面试题汇总.pdf</a> 6. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247485664&idx=1&sn=435f9f515a8f881642820d7790ad20ce&scene=21#wechat_redirect" target="_blank">Idea 快捷键大全.pdf</a> ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/1/2883e86e-3eff-404a-8943-0066e5e2b454.png)
相关专辑:
Linux专题