# CentOS8 安装 MySQL8.0(RPM) [作者博客](https://blog.51cto.com/u_11261718) [原文地址](https://blog.51cto.com/u_11261718/2465227) > 环境:Linux centos8 4.18.0-80.el8.x86_64、Mysql8.0.18 ## 1、Mysql官网下载RPM包 ![CentOS8 安装 MySQL8.0(RPM)_linux](https://cdn.learnku.com/uploads/images/201912/21/32495/2TNOZ7kvVK.png!large) ![CentOS8 安装 MySQL8.0(RPM)_mysql_02](https://cdn.learnku.com/uploads/images/201912/21/32495/Dx4o27N0Ll.png!large) ## 2、检查是否安装过 ```html rpm -qa | grep -i mysql ``` ## 3、卸载之前的安装 ```html rpm -e --nodeps 软件名 //强力删除,对相关依赖的文件也进行强力删除 ``` ## 4、安装客户端(mysql-client) ```html rpm -ivh rpm包 * 安装mysql-community-common-8.0.18 * 安装mysql-community-libs-8.0.18 * 安装mysql-community-client-8.0.18(前两个是其依赖) ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_03](https://cdn.learnku.com/uploads/images/201912/21/32495/jO9Z6eEuME.png!large) ![CentOS8 安装 MySQL8.0(RPM)_mysql_04](https://cdn.learnku.com/uploads/images/201912/21/32495/nvlaQ3ER3H.png!large) ![CentOS8 安装 MySQL8.0(RPM)_mysql_05](https://cdn.learnku.com/uploads/images/201912/21/32495/dzHM5ERPtc.png!large) ## 5、安装服务端(mysql-server) ![CentOS8 安装 MySQL8.0(RPM)_linux_06](https://cdn.learnku.com/uploads/images/201912/21/32495/Jtq8ljgSZ2.png!large) ![CentOS8 安装 MySQL8.0(RPM)_linux_07](https://cdn.learnku.com/uploads/images/201912/21/32495/6rIYWqftHM.png!large) ## 6、查看是否安装成功 ```html 有以下方式查看: * ps -ef | grep mysql * cat /etc/group | grep mysql * cat /etc/password | grep mysql * mysqladmin --version ... ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_08](https://cdn.learnku.com/uploads/images/201912/21/32495/aEIQJoMWwS.png!large) ![CentOS8 安装 MySQL8.0(RPM)_mysql_09](https://cdn.learnku.com/uploads/images/201912/21/32495/zwDTan2oHb.png!large) ![CentOS8 安装 MySQL8.0(RPM)_mysql_10](https://cdn.learnku.com/uploads/images/201912/21/32495/9bee6xP8Gr.png!large) ## 7、初始化mysql ```html mysqld --initialize //创建数据文件目录和mysql系统数据库 产生随机root密码 ``` ## 8、启动mysql服务 ```html systemctl start mysqld ``` ![CentOS8 安装 MySQL8.0(RPM)_linux_11](https://cdn.learnku.com/uploads/images/201912/21/32495/V4NWWzkibu.png!large) ```html 启动失败,因为/var/lib/mysql目录权限不够 ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_12](https://cdn.learnku.com/uploads/images/201912/21/32495/IJ2fjGgagY.png!large) ## 9、/var/lib/mysql目录权限授权 ```html chown -R mysql:mysql /var/lib/mysql/ ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_13](https://cdn.learnku.com/uploads/images/201912/21/32495/Zt9K5iXW3S.png!large) ## 10、启动mysql服务 ```html systemctl start mysqld //启动 ps -ef | grep mysql //查看mysql服务 ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_14](https://cdn.learnku.com/uploads/images/201912/21/32495/sEFjMpxsAi.png!large) ## 11、查看初始化随机生成的root密码 ```html cat /var/log/mysqld.log | grep password ``` ![CentOS8 安装 MySQL8.0(RPM)_linux_15](https://cdn.learnku.com/uploads/images/201912/21/32495/hvgBsYLCbs.png!large) ## 12、安全设置 ```html mysql_secure_installation ``` ![CentOS8 安装 MySQL8.0(RPM)_linux_16](https://cdn.learnku.com/uploads/images/201912/21/32495/LjRTaqHLuG.png!large) ![CentOS8 安装 MySQL8.0(RPM)_mysql_17](https://cdn.learnku.com/uploads/images/201912/21/32495/XIiZ6Cifxi.png!large) ## 13、mysql登录 ```html mysql -uroot -p //随机密码登录 ``` ![CentOS8 安装 MySQL8.0(RPM)_linux_18](https://cdn.learnku.com/uploads/images/201912/21/32495/Q9wTS3ocCT.png!large) ## 14、重置密码(Mysql8.0+有变化) ```html 先把root的旧密码置空 use mysql; update user set authentication_string='' where user='root'; 备注:Mysql5.7+ password字段 已改成 authentication_string字段 ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_19](https://cdn.learnku.com/uploads/images/201912/21/32495/hTmWm4KY6g.png!large) ```html 重置成新密码 alter user 'root'@'localhost' identified by 'newpassword'; 备注:Mysql8.0修改密码方式已有变化(此处是个坑,需要注意) Mysql8.0之前: update user set password=password('root') where user='root'; ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_20](https://cdn.learnku.com/uploads/images/201912/21/32495/TlnCt0b6CK.png!large) ## 15、退出后使用新密码再登录mysql ```html mysql -uroot -proot ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_21](https://cdn.learnku.com/uploads/images/201912/21/32495/GsubKaox9h.png!large) ## 16、如何停止、重启和查看mysql服务 ```html systemctl stop mysqld //停止服务 systemctl restart mysqld //重启服务 systemctl status mysqld //查看服务 ``` ## 17、mysql的相关安装目录文件 ```html /usr/bin //相关命令 ``` ![CentOS8 安装 MySQL8.0(RPM)_linux_22](https://cdn.learnku.com/uploads/images/201912/21/32495/rzdrV1NbjT.png!large) ```html /usr/share/mysql //配置文件目录 ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_23](https://cdn.learnku.com/uploads/images/201912/21/32495/bRGS2J2pnT.png!large) ```html /var/lib/mysql //数据库文件存放目录 ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_24](https://cdn.learnku.com/uploads/images/201912/21/32495/wQYYNnmAeJ.png!large) ```html /etc/my.cnf //mysql的启动配置文件 ``` ![CentOS8 安装 MySQL8.0(RPM)_mysql_25](https://cdn.learnku.com/uploads/images/201912/21/32495/avhSyrSOim.png!large) ## 18、后记 ```html my.ini //windows操作系统下的配置文件 my.cnf //linux操作系统下的配置文件 mysqld //是后台守护进程,即mysql daemon mysql //是客户端命令行 ```