Linux Yum安装MySQL
yum安装MySQL
-
下载yum源
# 下载地址 https://dev.mysql.com/downloads/repo/yum # 此处以下方文件为例:该文件下载地址: https://dev.mysql.com/get/mysql80-community-release-el8-4.noarch.rpm wget mysql80-community-release-el8-4.noarch.rpm
-
安装rpm
# 安装下载的文件 yum install -y mysql80-community-release-el8-4.noarch.rpm # 上诉出现 Nothing to do!, 则已经安装或者未卸载干净 yum clean all yum makecache
-
安装MySQL
# 安装MySQL yum install -y mysql-community-server
若提示一下内容,则执行:
yum module disable mysql
MySQL 8.0 Community Server 396 kB/s | 2.6 kB 00:00 MySQL Connectors Community 411 kB/s | 2.6 kB 00:00 MySQL Tools Community 428 kB/s | 2.6 kB 00:00 All matches were filtered out by modular filtering for argument: mysql-community-server Error: Unable to find a match: mysql-community-server
-
MySQL操作命令
# 查看状态 systemctl status mysqld # 启动 systemctl start mysqld # 停止 systemctl stop mysqld # 开机启动
-
修改密码、远程连接
# 修改密码
1. 查看默认密码
grep 'temporary password' /var/log/mysqld.log
2022-08-25T16:51:47.483033Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ITFeX#M45scx
如果没有默认密码,则在/etc/my.cnf中的[mysqld]下添加skip-grant-tables
# 登录mysql
mysql -uroot -p"ITFeX#M45scx" # 如果添加了skip-grant-tables,则密码随便填
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@rooT@123';
# 远程连接
CREATE USER 'root'@'%' IDENTIFIED BY '密码';
GRANT ALL ON *.* TO 'root'@'%';
# 刷新
flush privileges