系统是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我也没办法了,不会设置