,命令行实操完整版)
前言开发和服务器部署基本都是 Linux 环境本篇手把手教你CentOS8 和 Ubuntu两大主流系统命令行安装 MySQL全程命令复制即用无多余操作。一、通用前置准备关闭防火墙、关闭 SELinux服务器环境可选bash运行# CentOS systemctl stop firewalld systemctl disable firewalld # Ubuntu ufw allow 3306二、CentOS8 安装 MySQL安装 MySQL 源bash运行dnf install -y https://dev.mysql.com/get/mysql80-community-release-el8-3.noarch.rpm安装 MySQL 服务bash运行dnf install -y mysql-community-server启动并设置开机自启bash运行systemctl start mysqld systemctl enable mysqld查看初始临时密码bash运行grep temporary password /var/log/mysqld.log登录修改密码bash运行mysql -uroot -p ALTER USER rootlocalhost IDENTIFIED BY Root123456;开启远程连接sqlCREATE USER root% IDENTIFIED BY Root123456; GRANT ALL PRIVILEGES ON *.* TO root% WITH GRANT OPTION; FLUSH PRIVILEGES;三、Ubuntu 安装 MySQL更新软件源bash运行apt update直接安装bash运行apt install mysql-server -y启动自启bash运行systemctl start mysql systemctl enable mysql进入配置授权远程访问bash运行sudo mysqlsqlALTER USER rootlocalhost IDENTIFIED WITH mysql_native_password BY 123456; CREATE USER root% IDENTIFIED BY 123456; GRANT ALL ON *.* TO root%; FLUSH PRIVILEGES;修改配置允许外网连接编辑/etc/mysql/mysql.conf.d/mysqld.cnf把bind-address 127.0.0.1注释掉重启 MySQL。四、常用运维命令bash运行# 启动/停止/重启 systemctl start mysqld systemctl stop mysqld systemctl restart mysqld # 查看状态 systemctl status mysqld