WSL Ubuntu 18.04 中安装 MySQL 5.7

更新日期: 2019-09-15 阅读次数: 18059 字数: 276 分类: MySQL

sudo apt install mysql-server-5.7
sudo mysqld

启动失败

2018-08-15T01:08:41.167354Z 0 [ERROR] Could not create unix socket lock file /var/run/mysqld/mysqld.sock.lock.
2018-08-15T01:08:41.167378Z 0 [ERROR] Unable to setup unix socket lock file.

修改启动方式

sudo service mysql start

之后问题解决,但是没有默认密码。设置 root 账号密码

sudo mysql_secure_installation

设置默认密码之后,依然无法访问。

$ mysql -uroot -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

需要 sudo

sudo mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu)

新建一个不需要 sudo 登陆的账号

mysql> create user 'zhongwei'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to 'zhongwei'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

zhongwei@WIN-1810131157:~$ mysql -uzhongwei -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu)

Mysql Workbench

在 WSL 中安装好 mysql 之后,使用 windows 端安装的 mysql workbench 访问 127.0.0.1 即可访问。

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

将密码安全级别降低即可

mysql> SET GLOBAL validate_password_policy=LOW;

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式