首页 > 数据库 >如何在WSL 2 (Ubuntu) 中安装MySQL8.0

如何在WSL 2 (Ubuntu) 中安装MySQL8.0

时间:2024-02-28 21:45:58浏览次数:22  
标签:sudo Ubuntu WSL MySQL8.0 mysql MySQL Yes password root

前言

​ 在CSDN上找了一圈如何在WSL2上的Ubuntu下载Mysql8.0,并于Windows主机上的Navicat进行连接的教程,找了七八篇,跟着走了一遍,结果全部失败!全部失败!

​ 于是我果断的选择谷歌搜索,找到一篇一次成功的文章,这里是原文.这里仅做转载,感谢作者大佬!

​ 在这里贴出自己的版本号.

image-20240228210942143 image-20240228211148474

1. 升级WSL2 Ubuntu

sudo apt update && sudo apt upgrade

这里可能需要输入管理员密码.

2. 下载Mysql(默认最新版)

sudo apt install mysql-server

检查mysql版本

mysql --version

3. 进行mysql的安全设置

You may also want to run the included security script. This changes some less secure default options for things like remote root logins and sample users.

您可能还想运行所包含的安全脚本。这改变了一些不太安全的默认选项,如远程root登录和示例用户。

  1. 启动mysql
sudo service mysql start
  1. 运行安全脚本
sudo mysql_secure_installation
  1. 你看看到如下输出(可以参照我的选择)

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: **n ** //你是否要下载密码验证组件以设置强度足够的密码

Please set the password for root here.

New password: root

Re-enter new password: root

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y //默认有一个匿名用户,是否进行删除

Success.

Note: 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) : n //是否移除测试数据库

… skipping.

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!

4. 确定mysql正在运行

  1. 进入mysql
sudo mysql
  1. 查看可用数据库
show databases;

image-20240228212126981

5. 允许远程连接

这里我想吐槽的是,CSDN很多帖子都会教授我们如何允许mysql8的远程登录,但是在这里显得如此简单...

在上一步运行show...的地方继续运行

ALTER
USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

请注意你的密码设置,这里演示为'root'

退出mysql

exit

6. 使用客户端进行连接

原文给出的示例客户端为HeidiSQL,但是我使用的是Navicat

  • 连接名:任取
  • 主机:localhost
  • 默认端口:3306
  • 用户名:root
  • 密码:root

image-20240228212519100

吐槽一下这里的主机名,看来其它博文都需要自行去找wsl的ifconfig,而这里只需localhost...

演示到这里就结束了,如果有更多需求,请自行参考[原文](How to install MySQL on WSL 2 (Ubuntu) · Pen-y-Fan)

标签:sudo,Ubuntu,WSL,MySQL8.0,mysql,MySQL,Yes,password,root
From: https://www.cnblogs.com/jiuyou2020/p/18041957

相关文章

  • ubuntu串口重命名(串口绑定)
    不同方法在于rules文件的编写。rules文件编写方法一:针对不同转换芯片在未插入和插入USB设备时,分别通过lsusb命令查看所连接的USB设备。可以看出硬件ID为"1b3f:8301"在/etc/udev/rules.d中创建.rules文件,比如我的是my.rules,输入以下内容:KERNEL=="ttyUSB*",ATTRS{idVe......
  • 解决Ubuntu安装汉语语言包后汉语中文是灰色不能选中的问题
    安装版本ubuntu版本22.04最小化安装安装中不升级问题通过最小化且不更新安装后,需要进行自行安装语言包,更换语言的操作,在【语言支持】中发现在语言安装中汉语无法选中确认语言包已经安装解决其实在这个地方不是进行语言选择的地方,而是需要在其他地方进行设置打开设置中......
  • ubuntu20.04开启ftp服务
    sudoaptupdatesudoaptinstallvsftpdsudovi/etc/vsftpd.conflocal_enable=YES允许本地用户通过FTP登录到服务器 取消注释并将其设置为:chroot_local_user=YES这将限制本地用户的FTP访问仅限于其家目录。 sudosystemctlstartvsftpd#启动sudosystemctl......
  • arm64-ubuntu2204-opencv4.7.0源码编译
    参考:https://blog.csdn.net/weixin_43863869/article/details/128552342https://blog.csdn.net/weixin_39956356/article/details/102643415https://blog.csdn.net/quicmous/article/details/112714641 cdopencv-4.7.0 sudoapt-getinstallbuild-essentiallibgtk2.0-d......
  • ubuntu日常开发问题集合
    VMware虚拟机和主机间复制粘贴共享剪贴板https://blog.csdn.net/appleKevin/article/details/134227123#!/bin/bashset-oerrexit######################################root@second:/opt#lsb_release-a#NoLSBmodulesareavailable.#DistributorID:Ubuntu#De......
  • Ubuntu如何进救援模式
    linux的救援模式-1详解在Ubuntu中引导到救援模式或紧急模式这篇教程将介绍如何在Ubuntu22.04、20.04和18.04LTS版本中引导到救援Rescue模式或紧急Emergency模式。你可能已经知道,在RHEL7、RHEL8、Ubuntu16.04LTS及其更新的版本的Linux发行版中运行等级R......
  • ubuntu无法安装lrzsz
    ubuntu无法安装lrzszroot@ubuntu:/opt/test#aptinstalllrzszReadingpackagelists...DoneBuildingdependencytreeReadingstateinformation...DoneE:Unabletolocatepackagelrzsz解决办法:$sudoadd-apt-repositorymain$sudoadd-apt-repositor......
  • ubuntu16 安装cmake
    CMakedeveloperteaminKitwareIncprovidesAPTrepositiory.ItallowsyoutoinstalllatestCMakeviaapt-get.IfyouareusingaminimalUbuntuimageoraDockerimage,youmayneedtoinstallthefollowingpackages:sudoapt-getupdatesudoapt-getin......
  • Ubuntu22.04下载显卡驱动和CUDA+cuDNN
    注:笔记本电脑-显卡RTX4060-CUDA11.8-cuDNN8.9.7 1:显卡驱动已经安装驱动的,以此卸载已下载驱动sudoapt-getremove--purgenvidia-* 新机器直接进行以下#查看驱动列表sudoaptinstallaptitudesudoaptitudesearchnvidia-driver-*显卡驱动一般选择最新......
  • Ubuntu2204安装微信deepin-wine
    前言:因网页版微信不继续支持,才出此下策。1:安装deepin-wine软件仓库更新软件源sudoapt-getupdate添加deepin-wine仓库wget-O-https://deepin-wine.i-m.dev/setup.sh|sh2:安装软件sudoapt-getinstallcom.qq.weixin.deepin将com.qq.weixin.deepin替换为下列包名,可......