1. 程式人生 > 實用技巧 >WSL2 配置及ubuntu18.04安裝mysql8.0+

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

wsl2 完整配置

參考將WSL2作為生產力工具

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

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/目錄下
# 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

忘記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

# 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;

+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| 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

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

windows

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