WSL 安装MySQL

系统是WSL上的Ubuntu 20.04

方法1(失败)

根据官方文档安装最新版MySQL:

https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/#apt-repo-fresh-install

会出现mysql: unrecognized service的问题,无法解决遂放弃。

方法2(只能使用root用户)

将之前安装的mysql文件删除干净

# 卸载mysql
sudo apt purge mysql-server
dpkg --list | grep mysql | grep ii # 查找剩什么包没删一起删了,例如mysql-apt-config
sudo apt purge mysql-apt-config
sudo apt autoremove
# 查找残余配置文档并删除
sudo updatedb
locate -i mysql
# 删除mysql配置文件

然后直接从apt安装

sudo apt install mysql-server

安装未设置密码密码全为空
使用测试,发现普通用户无法使用,

$ sudo service mysql restart
 * Stopping MySQL database server mysqld      [ OK ]                                                                                                                                    
 * Starting MySQL database server mysqld                                                                                                               
su: warning: cannot change directory to /nonexistent: No such file or directory

$ service mysql status
 * MySQL is stopped.

$ mysql -u user -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

只能先登录root用户

$ su root
$ service mysql status
 * /usr/bin/mysqladmin  Ver 8.0.26-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))
Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version          8.0.26-0ubuntu0.20.04.2
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/run/mysqld/mysqld.sock
Uptime:                 2 min 4 sec

Threads: 2  Questions: 10  Slow queries: 0  Opens: 436  Flush tables: 3  Open tables: 27  Queries per second avg: 0.080
$ mysql -u root -p # 密码未设置为空
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.26-0ubuntu0.20.04.2 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

我一般喜欢用user而不是root,不过mysql好像只能用root我也没办法了,不会设置

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值