Ubuntu安装Mysql并实现远程登录【ubuntu 24.04/mysql 8.0.39】

一、安装MySQL

bash 复制代码
sudo apt update  # 更新软件源
sudo apt install mysql-server -y  # 安装
mysql --version  # 查看版本
sudo systemctl status mysql  # 查看运行状态
netstat -tln  # 以数字ip形式显示mysql的tcp监听状态

二、设置MySQL的root密码

bash 复制代码
sudo mysql -u root  # 使用root无密码登录
alter user 'root'@'localhost' identified with mysql_native_password by '123456';  # 为root添加密码
exit;

三、设置允许root远程登录

bash 复制代码
sudo mysql -u root -p  # 使用root有密码登录
use mysql;  # 使用名为mysql的数据库
select host,user from user;  # 查看host,user
update user set host='%' where user='root';  # 运行root远程登录
flush privileges;  # 权限刷新
select host,user from user; # 查看host,user
exit;

四、允许其他ip远程登录

bash 复制代码
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0  # 修改 crl+o写入  回车  crl+x 退出
sudo systemctl restart mysql  # 修改后重启

五、使用主机连接测试

bash 复制代码
mysql -u root -p -h ip # ip替换为实际MySQL服务器ip

参考(第一个最有用)

相关推荐
一叶知秋yyds8 分钟前
Ubuntu 虚拟机安装 OpenClaw 完整流程
linux·运维·ubuntu·openclaw
喵了几个咪1 小时前
如何在 Superset Docker 容器中安装 MySQL 驱动
mysql·docker·容器·superset
Chasing__Dreams2 小时前
Mysql--基础知识点--95--为什么避免使用长事务
数据库·mysql
数据知道3 小时前
claw-code 源码分析:OmX `$team` / `$ralph`——把 AI 辅助开发从偶发灵感变成可重复流水线
数据库·人工智能·mysql·ai·claude code·claw code
__土块__4 小时前
大厂后端一面模拟:从线程安全到分布式缓存的连环追问
jvm·redis·mysql·spring·java面试·concurrenthashmap·大厂后端
做个文艺程序员4 小时前
深入 MySQL 内核:MVCC、Buffer Pool 与高并发场景下的极限调优
数据库·mysql·adb
数厘5 小时前
2.4MySQL安装配置指南(电商数据分析专用)
数据库·mysql·数据分析
camellias_5 小时前
ubuntu(二)ubuntu18.04安装mysql8
linux·ubuntu·adb
藤谷性能5 小时前
Ubuntu 22.04:安装串口调试助手CoolTerm
linux·运维·ubuntu·串口·coolterm
一江寒逸5 小时前
零基础从入门到精通MySQL(下篇):精通篇——吃透索引底层、锁机制与性能优化,成为MySQL实战高手
数据库·mysql·性能优化