ubuntu 服务器中mysql的安装与连接

1.mysql的安装与初始化

复制代码
sudo apt update
sudo apt install mysql-server-8.0 mysql-client-8.0 
sudo mysql # 进入mysqlshell后输入下面的命令设置mysql的密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

2.mysql 进行远程连接的时候报错记录

2.1.1 报错信息

2013 - Lost connection to MySQL server at 'handshake: reading initial communication packet', system error: 11

2.1.2 解决方案

修改配置文件配置允许远程连接

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

其中之' /etc/mysql/mysql.conf.d/mysqld.cnf ' 是ubuntu22.04中mysql8.0.35的具体配置文件路径,不同的版本文件路径有些差异,读者可以从/etc/mysql/mysql.conf 中获取信息。

2.2.1 报错信息

Host '' is not allowed to connect to this MySQL server

2.2.2 解决方案

Host is not allowed to connect to this MySQL server解决方法-CSDN博客

修改root用户允许远程访问后如果还是无法链接记得重新启动mysql服务

bash 复制代码
sudo systemctl restart mysql

3 大功告成

相关推荐
九丝城主1 小时前
2025使用VM虚拟机安装配置Macos苹果系统下Flutter开发环境保姆级教程--中篇
服务器·flutter·macos·vmware
码出钞能力1 小时前
linux内核模块的查看
linux·运维·服务器
KellenKellenHao2 小时前
MySQL数据库主从复制
数据库·mysql
Maki Winster3 小时前
Peek-Ubuntu上Gif录制工具-24.04LTS可装
linux·ubuntu·peek
小皮侠3 小时前
nginx的使用
java·运维·服务器·前端·git·nginx·github
一只fish3 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(16)
数据库·mysql
Maki Winster4 小时前
在 Ubuntu 下配置 oh-my-posh —— 普通用户 + root 各自使用独立主题(共享可执行)
linux·运维·ubuntu
叁沐5 小时前
MySQL 07 行锁功过:怎么减少行锁对性能的影响?
mysql
ddfa12345 小时前
XML 笔记
xml·服务器
海外空间恒创科技5 小时前
一台香港原生ip站群服务器多少钱?
服务器·网络协议·tcp/ip