Ubuntu MySQL

在安装前,首先看你之前是否安装过,如果安装过,但是没成功,就要先卸载。

一、卸载

1.查看安装

bash 复制代码
dpkg --list | grep mysql

有东西,就说明您之前安装过mysql。

2.卸载

先停掉server

bash 复制代码
sudo systemctl stop mysql.service

查看状态

bash 复制代码
systemctl status mysql.service

现在已经停掉了。

下面开始卸载

bash 复制代码
sudo apt remove mysql-common
bash 复制代码
sudo apt autoremove --purge mysql-server
bash 复制代码
dpkg -l | grep ^rc| awk '{print$2}'| sudo xargs dpkg -P

检查卸载情况

bash 复制代码
dpkg --list | grep mysql

如果说明也没有 就说明卸载干净了,最后输入

bash 复制代码
 sudo apt autoremove --purge mysql-apt-config

到这里就全部结束了。

二、安装

1.更新

bash 复制代码
sudo apt-get update

2.mql 服务端和客户端

bash 复制代码
sudo apt-get install mysql-server
bash 复制代码
sudo apt-get install mysql-client

修改密码

bash 复制代码
mysql -uroot -p

因为没有设置密码,所以你是不知道密码多少的。所以先用别的账号登录再去修改密码。

bash 复制代码
sudo cat /etc/mysql/debian.cnf
bash 复制代码
mysql -u debian-sys-maint -p

登录后去设置一些属性才能修改密码。直接修改会提示

ERROR 1819 (HY000): Your password does not satisfy the current polic

进入mysql后执行

bash 复制代码
use mysql;
select user,plugin from user;
update user set plugin='mysql_native_password' where user='root';

查看密码规则,修改密码规则

bash 复制代码
SHOW VARIABLES LIKE 'validate_password%';
bash 复制代码
SET GLOBAL validate_password.length = 6;
SET GLOBAL validate_password.mixed_case_count = 0;
SET GLOBAL validate_password.number_count = 0;
SET GLOBAL validate_password.special_char_count = 0;

下面就可以设置密码了

bash 复制代码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

设置完 exit

然后就可以用root登录了。

三、数据库操作

我们这边使用mysql workbench来操作数据库。

下载地址MySQL :: Download MySQL Workbench (Archived Versions)

选择和你系统匹配的就好。

我是20.04的,所以选了一个20.04的 8.0.28。

安装好运行是这样的

然后点击下面这个database,输入你之前设置的密码就能连接了。

相关推荐
tntxia15 小时前
linux curl命令详解_curl详解
linux
扛枪的书生18 小时前
Linux 网络管理器用法速查
linux
SkyWalking中文站20 小时前
认识 Horizon UI · 1/17:SkyWalking 新一代可观测性控制台
运维·前端·监控
顺风尿一寸21 小时前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
雪梨酱QAQ1 天前
Kubeneters HA Cluster部署
运维
江华森1 天前
Spring Cloud 微服务全栈实战:从 Eureka 到 Docker Compose 一文贯通
运维
江华森1 天前
Matplotlib 数据绘图基础入门
运维
XIAOHEZIcode1 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
江华森1 天前
NumPy 数值计算基础入门
运维
唐青枫1 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux