使用wsl2 安装mysql,并通过windows连接

1、执行 sudo apt install mysql-server 安装mysql-server。本文mysql-server的版本是8.0

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

2、验证安装 mysql -u root -p

3、修改root用户的远程访问权限 update user set host='%' where user='root';

4、刷新权限表FLUSH PRIVILEGES;

5、重启mysql 服务

错误记录

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

  2. 进入mysql,刷新权限表 flush privileges;

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

    use mysql;

    查看用户列表select host, user, authentication_string, plugin from user;

    将旧密码制空 update user set authentication_string='' where user='root';

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

    use mysql;

    FLUSH PRIVILEGES;

    ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

参考连接 WSL2 配置及ubuntu18.04安装mysql8.0+

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容