win10 bash mysql_win10子系统之MySQL的安装、访问、以及win10访问

如何安装Ubunt?

我是在子系统服务刚出来时就已经开启该服务(当时装的是kali),时间久远, 如何开启服务和安装子系统已经不方便截图, 且网上教程已近多如星辰,就不在赘言! 本人安装的是Ubuntu 18.04

引用知乎专栏

安装Ubuntu之补充

1.修改root账户密码: sudo passwd root

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

2.切换为root用户(有些操作root账户权限才可以): su root

Password:

root@DESKTOP-R3SRO54:/home#

MySQL相关操作

( 一 ) 安装:

命令: sudo apt-get install mysql-server

注意: Ubuntu安装过程中不会出现让你设定密码的过程, 所以通过`mysql -u root -p 登录时(关于启动报错解决,请看下文!), 出现输入密码时,有两种处理方式:

方式1: 直接按Enter键即可(默认为空)!

方式2: 命令:

cd /etc/mysql/

vi debian.cnf

host = localhost

user = debian-sys-maint

#这是系统提供的方法

password = pSoUYT8SfB2R7sy2

socket = /var/run/mysqld/mysqld.sock

修改MySQL密码

#登入MySQL执行以下操作

use mysql

update mysql.user set authentication_string=password('自定义密码') where user='root';

flush privileges;//刷新MySQL的系统权限相关表

关于端口3306修改以及win10访问的原因及方式

如果你windows10本身安装了MySQL服务, 则会使用3306端口,windows10端口是和子系统共用的, 所以为了能够在windows10系统内通过navicat或者cmd等方式连接子系统MySQL, 则必须选择更改其中一个服务端口号, 建议更改子系统中该服务端口号!

命令: cd /etc/mysql/mysql.conf.d/

root@DESKTOP-R3SRO54:/# cd /etc/mysql/mysql.conf.d

root@DESKTOP-R3SRO54:/etc/mysql/mysql.conf.d# ls

mysqld.cnf mysqld_safe_syslog.cnf

命令: vi mysqld.cnf #修改完成后重启MySQL服务

user = mysql

pid-file = /var/run/mysqld/mysqld.pid

socket = /var/run/mysqld/mysqld.sock

# 修改端口号

port = 9999

basedir = /usr

datadir = /var/lib/mysql

tmpdir = /tmp

lc-messages-dir = /usr/share/mysql

( 二 )启动:

注意: 启动方式暂时仅测试了Ubuntu, Debian!等未测试

命令: sudo service mysql start

注意: 可能会出现的错误: 【No directory, logging in with HOME=/】

解决方法

usermod -d /var/lib/mysql/ mysql

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

chown -R mysql:mysql /var/lib/mysql

#重启mysql即可

sudo service mysql restart

( 三 ) 查看状态、重启、停止

查看状态

命令: sudo service mysql status

* /usr/bin/mysqladmin Ver 8.42 Distrib 5.7.23, for Linux on x86_64

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Server version 5.7.23-0ubuntu0.18.04.1

Protocol version 10

Connection Localhost via UNIX socket

UNIX socket /var/run/mysqld/mysqld.sock

Uptime: 1 hour 35 min 53 sec

重启

命令: sudo service mysql restart

停止

命令: sudo service mysql stop

( 四 ) windows10访问子系统MySQL

命令: mysql -h127.0.0.1 -P [你自定义的端口号] -u root -p

#注意端口P和密码p大小写的区别

C:\Users\anonymous>mysql -h127.0.0.1 -P 9999 -u root -p

Enter password: *********

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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>

----欢迎转载, 如转载, 请说明转载出处******欢迎转载, 如转载, 请说明转载出处

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值