一、安装前、检查系统是否安装MYSQL
rpm -qa | grep mysql
注:如果有安装 ,可执行 rpm -e 或者 rpm -e --nodeps mysql (强力删除模式,可删除有依赖的其他文件)
二、安装MySQL
①、rpm下载地址(MySQL :: Begin Your Download)
②、从自己的电脑导入到云主机或者虚拟机上。
③、安装
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum update
yum install mysql-server
④、权限设置
chown mysql:mysql -R /var/lib/mysql
⑤、初始化mysql
mysqld --initialize
⑥、启动
systemctl start mysqld
⑦、启动失败,查看日志(/var/log/mysqld.log)
[root@cy-ed03-lvs ~]# cat /var/log/mysqld.log
2021-04-25T08:35:13.397545Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.24) initializing of server in progress as process 22624
2021-04-25T08:35:13.412945Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-25T08:35:14.570523Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-04-25T08:35:16.048822Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: t)QWVI#94bKk
2021-04-25T08:35:46.059895Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.24) starting as process 22698
2021-04-25T08:35:46.106747Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-25T08:35:46.106836Z 1 [ERROR] [MY-012271] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2021-04-25T08:35:46.106870Z 1 [ERROR] [MY-012278] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2021-04-25T08:35:46.106913Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2021-04-25T08:35:46.107025Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2021-04-25T08:35:46.107107Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-04-25T08:35:46.107841Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24) MySQL Community Server - GPL.
表示该文件必须设置为可写。
解决方法:chmod -R 777 /var/lib/mysql
⑧、重新启动 ,启动成功
⑨、登录
回车之后提示输出初始密码
初始密码:(初始密码是冒号之后内容)
[root@localhost ~]# grep "temporary password" /var/log/mysqld.log
2021-04-30T15:40:38.048655Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: y(ffZXKFr1mS
登录:
mysql -uroot -p
修改密码
alter user 'root'@'localhost' identified by '新密码';