当前位置: 首页 > news >正文

linux中mysql如何远程连接

linux中mysql如何远程连接

两个步骤:

第一:让root允许远程登录

update user set host = '%' where user = 'root';

第二:给予root用户最大数据库权限

grant all privileges on *.* to 'root'@'%' identified by '123456';
flush privileges;

实操:

[root@bogon ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.40 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> select host, user from user;
+-----------+------+
| host      | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1       | root |
| bogon     |      |
| bogon     | root |
| localhost |      |
| localhost | root |
+-----------+------+
6 rows in set (0.01 sec)mysql> update user set host = '%' where user = 'root';select host, user from user;
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
+-----------+------+
| host      | user |
+-----------+------+
| %         | root |
| 127.0.0.1 | root |
| ::1       | root |
| bogon     |      |
| bogon     | root |
| localhost |      |
+-----------+------+
6 rows in set (0.00 sec)mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.02 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> exit
Bye[root@bogon ~]# systemctl restart mysqld[root@bogon ~]# systemctl status mysqld
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)Active: active (running) since Wed 2025-09-17 19:50:47 CST; 1min 54s agoDocs: man:mysqld(8)https://dev.mysql.com/doc/refman/en/using-systemd.htmlMain PID: 1473 (mysqld)Tasks: 21 (limit: 10892)Memory: 439.8MCPU: 1.196sCGroup: /system.slice/mysqld.service└─1473 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnfSep 17 19:50:48 bogon mysqld[1473]: 2025-09-17 19:50:48 1473 [Note] InnoDB: 128 rollback segment(s) are active.
Sep 17 19:50:48 bogon mysqld[1473]: 2025-09-17 19:50:48 1473 [Note] InnoDB: Waiting for purge to start
Sep 17 19:50:48 bogon mysqld[1473]: 2025-09-17 19:50:48 1473 [Note] InnoDB: 5.6.40 started; log sequence number 1626087
Sep 17 19:50:48 bogon mysqld[1473]: 2025-09-17 19:50:48 1473 [Note] Server hostname (bind-address): '*'; port: 3306
Sep 17 19:50:48 bogon mysqld[1473]: 2025-09-17 19:50:48 1473 [Note] IPv6 is available.
Sep 17 19:50:48 bogon mysqld[1473]: 2025-09-17 19:50:48 1473 [Note]   - '::' resolves to '::';
Sep 17 19:50:48 bogon mysqld[1473]: 2025-09-17 19:50:48 1473 [Note] Server socket created on IP: '::'.
Sep 17 19:50:48 bogon mysqld[1473]: 2025-09-17 19:50:48 1473 [Note] Event Scheduler: Loaded 0 events
Sep 17 19:50:48 bogon mysqld[1473]: 2025-09-17 19:50:48 1473 [Note] /application/mysql/bin/mysqld: ready for connections.
Sep 17 19:50:48 bogon mysqld[1473]: Version: '5.6.40'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)
[root@bogon ~]#

http://www.wxhsa.cn/company.asp?id=6926

相关文章:

  • 详细介绍:Python:OpenCV 教程——从传统视觉到深度学习:YOLOv8 与 OpenCV DNN 模块协同实现工业缺陷检测
  • 深入解析:PYcharm——pyqt音乐播放器
  • Day02
  • 专题:Python实现贝叶斯线性回归与MCMC采样数据可视化分析2实例|附代码数据
  • 威联通NAS如何导入本地docker镜像
  • 【学习笔记】拉格朗日插值
  • 一种将离散化状态方程映射为并行多处理器计算机的方法
  • 基本数据类型题目
  • 一种基于动作指令交互的动态活体检测技术,提升人脸识别安全性
  • [系统] Windows 已有office版本和visio不兼容的解决方案
  • CF 2127F Hamed and AghaBalaSar
  • AT_agc055_b [AGC055B] ABC Supremacy
  • “Sequential Thinking MCP Server 和codex等AI工具本身任务拆解功能对比
  • 基于错误xsleak 悬空标记 运用css利用帧计数 -- Pure leak ASIS CTF 2025
  • 网易伏羲:当算法遇见社交,解码游戏世界的连接密码
  • 在 CentOS 7 上安装Nginx和配置http代理
  • 题解:P2624 [HNOI2008] 明明的烦恼
  • 在AI技术快速实现创想的时代,挖掘新需求成为核心竞争力——某知名DevOps学习平台需求洞察
  • Windows Powershell 获取版本version
  • XXL-JOB (1)
  • 记录---Vue3对接UE,通过MQTT完成通讯
  • 《Real-Time Rendering》第一章 介绍
  • C语言基础
  • 公益站Agent Router注册送200刀额度竟然是真的
  • 数据集中valid的作用
  • 深入 RocketMQ 核心源码:从环境搭建到高可用设计的全方位解析
  • 单例模式
  • apache修改默认位置
  • 实用指南:YOLOv11的旋转目标检测改进-(扩展检测头支持旋转框预测,适配遥感场景)
  • 从零到顶会:NLP科研实战手册 - 实践