WSL2 配置及ubuntu18.04安装mysql8.0+

wsl2 完整配置#

参考将WSL2作为生产力工具

Copy
Installing, this may take a few minutes… WslRegisterDistribution failed with error: 0x800701bc Error: 0x800701bc WSL 2 ??? https://aka.ms/wsl2kernel Press any key to continue… 这是官方的讨论连接https://github.com/microsoft/WSL/issues/5393 这是安装文件下载链接https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

raw.githubusercontent.com 被墙解决方案#

修改hosts

Copy
sudo vi /etc/hosts 199.232.4.133 raw.githubusercontent.com

ws2 ubuntu18.04安装mysql8.0+#

1.下载最新的deb文件#

wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb

2. 解压包#

sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb

安装过程中提示选择安装版本,默认安装的就是8.0版本,所以直接选择“OK”确认即可

3. 执行安装#

sudo apt update

4. 安装mysql8.0 server#

sudo apt install mysql-server

安装过程中会提示设置root密码。按照提示输入即可

输入之后会出现选择加密方式的提示界面,我在网上的教程中看到默认的mysql8.0的加密方式与ubuntu18.04 不兼容,所以选择5.x的加密方式;建议选择下边的那个

·Use Legacy Authentication Method·

5. 验证安装,输入命令#

mysql -u root -p

错误记录#

1. 签名无效 NO_PUBKEY xxxxxxxxxxxxxx#

解决方式,设置可以并重新执行第三步命令

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 报错的key

eg:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8

2. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'#

解决方案: INSTALLING MYSQL 8.0 UNDER WSL 2 AND UBUNTU

  1. 下载mysql.server.sh启动脚本

wget https://raw.githubusercontent.com/mysql/mysql-server/8.0/support-files/mysql.server.sh

  1. 修改该文件并复制到/etc/init.d/目录下
Copy
# If you change base dir, you must also change datadir. These may get # overwritten by settings in the MySQL configuration files. basedir=/usr datadir=/var/lib/mysql # Default value, in seconds, afterwhich the script should timeout waiting # for server start. # Value here is overriden by value in my.cnf. # 0 means don't wait at all # Negative numbers mean to wait indefinitely service_startup_timeout=900 # Lock directory for RedHat / SuSE. lockdir='/var/lock/subsys' lock_file_path="$lockdir/mysql" # The following variables are only set for letting mysql.server find things. # Set some defaults mysqld_pid_file_path=/var/run/mysqld/mysqld.pid if test -z "$basedir"

mv mysql.server.sh /etc/init.d/mysql

chomd +x /etc/init.d/mysql

  1. 启动MySQL

sudo service mysql start

sudo service mysql stop

The server quit without updating PID file (/var/run/mysqld/mysqld.pid).#

运行 sudo service mysql start 出现如上报错.

  1. 如果该目录不存在则创建 /var/run/mysqld
  2. 创建文件touch mysqld.pid
  3. chmod -R 777 /var/run/mysql
  4. 重启服务: sudo service mysql start

忘记mysql8.0 root 密码,如何重置#

官网文档:B.3.3.2.3 Resetting the Root Password: Generic Instructions

参考: MySQL8.0 忘记 root 密码下如何修改密码

  1. 关闭mysql服务,使用 skip-grant-tables 跳过权限验证

vi /etc/mysql/mysql.conf.d/mysqld.cnf

Copy
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License, version 2.0, for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # The MySQL Server configuration file. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql log-error = /var/log/mysql/error.log skip-grant-tables
  1. 重启mysql服务

sudo service mysql start

  1. 键入mysql进入mysql命令行

刷新权限表

flush privileges;

  1. 查看root用户和密码字段先将密码滞空

use mysql;

select host, user, authentication_string, plugin from user;

Copy
+-----------+------------------+------------------------------------------------------------------------+-----------------------+ | host | user | authentication_string | plugin | +-----------+------------------+------------------------------------------------------------------------+-----------------------+ | localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | mysql_native_password | +-----------+------------------+------------------------------------------------------------------------+-----------------------+ 4 rows in set (0.01 sec)

将旧密码滞空

update user set authentication_string='' where user='root';

  1. 删除skip-grant-tables限制,重启mysql服务,重连mysql,并重置密码

use mysql;

FLUSH PRIVILEGES;

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

配置全局pip镜像#

linux#

~/.pip/pip.conf

Copy
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = pypi.tuna.tsinghua.edu.cn

windows#

Copy
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

wsl some issue#

WSL2 Input/output error#

解决方案1

Copy
wsl --shutdown wsl

解决方案2: 重新挂载

Copy
sudo umount /mnt/c sudo mount -t drvfs C:\\ /mnt/c

Reference#

wsl windows terminal config
wsl 配置 git-bash

posted @   JonPan  阅读(5578)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示
CONTENTS