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

Ubuntu下配置并远程连接MySQL

1、安装mysql-server

apt update
apt install mysql-server

2、修改配置文件/etc/mysql/mysql.conf.d/mysqld.cnf

bind-address            = 0.0.0.0
mysqlx-bind-address     = 0.0.0.0

3、启动并设置服务为开机自启动

systemctl enable mysql.service --now

4、查看服务状态

systemctl status mysql.service

5、配置远程连接

(1)配置mysql_native_password插件,以允许用口令连接

本地登录数据库,执行以下命令

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '自行设置连接密码';FLUSH PRIVILEGES;

(2)修改mysql数据库的host主机,以允许远程连接

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 changedmysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql> FLUSH PRIVILEGES;

(3)初始化mysql

mysql_secure_installation Press y|Y for Yes, any other key for No: yThere are three levels of password validation policy:LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  filePlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.New password: Re-enter new password: ……Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y- Dropping test database...
Success.- Removing privileges on test database...
Success.Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.All done! 

6、重启mysql服务

systemctl restart mysql

7、远程连接

使用navicat等连接工具就可以远程连接了。

http://www.xdnf.cn/news/19203.html

相关文章:

  • GVIM-您的化学多智能体助手
  • 如何用 Kotlin 在 Android 手机开发一个应用程序获取国家或地区信息
  • 瞬态数据表定义Fluent变量
  • [Godot] C#获取MenuButton节点索引
  • 将数据赋值到Word并下载
  • 2025.8.29总结
  • 从Cloudflare到EdgeOne:我的个人站点加速之旅与性能对比实测
  • Ubuntu 搭建 Solana 区块链开发环境 + Anchor 智能合约完整教程
  • Linux-搭建DNS服务器
  • C++异常处理指南:构建健壮程序的错误处理机制
  • WebSocket功能完整解析
  • 疯狂星期四文案网第54天运营日记
  • 【web3】十分钟了解web3是什么?
  • golang接口详细解释
  • Maya绑定:连接编辑器的简单使用
  • HGDB全文检索/中文分词的使用
  • 机器人电源电感的认证和认证细节,知多少?
  • Web网络开发 -- 常见CSS属性
  • 使用Docker搭建StackEdit在线MarkDown编辑器
  • 【论文阅读】CLIP: 从自然语言监督中学习可迁移的视觉模型
  • 【Depth与RGB对齐算法(D2C)】
  • 首次创建Django项目初始化
  • 沙箱操作工具
  • 计算机组成原理3-3-1:无符号数乘法运算的硬件逻辑实现
  • 学习做动画6.瞄准偏移
  • JavaScript初识:给小白的第一堂编程课
  • 大数据毕业设计选题推荐-基于大数据的痴呆症预测数据可视化分析系统-Spark-Hadoop-Bigdata
  • openEuler常用操作指令
  • AT_abc407_e [ABC407E] Most Valuable Parentheses
  • 客户案例 | 国际知名内衣品牌x甄知科技,领航IT服务新征程