WSL win10子系统linux-ubuntu 安装mysql
2019-08-02 本文已影响2人
eye33
0.若之前有装过mysql,需要先清除mysql相关的安装信息
apt-get remove mysql-server
apt-get autoremove mysql-server
apt-get remove mysql-common
rm /var/lib/mysql/ -R
rm /etc/mysql/ -R
apt-get autoremove mysql* --purge
apt-get remove apparmor
若win10系统本身就装过mysql,则先需要关闭win10的mysql服务.防止后续冲突
1.若是新装的WSL,则可以直接进行安装
查看可以安装的mysql版本
apt-cache show mysql-server
结果如下,可以看到,只有5.7版本
Package: mysql-server
Architecture: all
Version: 5.7.27-0ubuntu0.18.04.1
Priority: optional
Section: database
Source: mysql-5.7
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 107
Depends: mysql-server-5.7
Filename: pool/main/m/mysql-5.7/mysql-server_5.7.27-0ubuntu0.18.04.1_all.deb
Size: 9948
MD5sum: 2a07a1282769022eabcd5ca6e530db5e
SHA1: 756b151e18aa6ae5e37a829b75df308eb9c7bba6
SHA256: 4b41d8b3f32d4917f426c5959c2f20c300ee233752c9b3cf416d88253b65feb1
Homepage: http://dev.mysql.com/
Description-en: MySQL database server (metapackage depending on the latest version)
This is an empty package that depends on the current "best" version of
mysql-server (currently mysql-server-5.7), as determined by the MySQL
maintainers. Install this package if in doubt about which MySQL
version you need. That will install the version recommended by the
package maintainers.
.
MySQL is a fast, stable and true multi-user, multi-threaded SQL database
server. SQL (Structured Query Language) is the most popular database query
language in the world. The main goals of MySQL are speed, robustness and
ease of use.
Description-md5: b8b44aa3bf1e86bb2834ded6d9d869b5
Task: lamp-server
Supported: 5y
Package: mysql-server
Architecture: all
Version: 5.7.21-1ubuntu1
Priority: optional
Section: database
Source: mysql-5.7
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 162
Depends: mysql-server-5.7
Filename: pool/main/m/mysql-5.7/mysql-server_5.7.21-1ubuntu1_all.deb
Size: 9940
MD5sum: d04ea92f904b8ab2fb9131c736aa21e2
SHA1: 981e321230bde35f71e0070284c2339af8b43c59
SHA256: 35963cb109420749d8e2aa2c9eb1eeae2c2fb8bd68d8eb6d7a49822a4c00f7af
Homepage: http://dev.mysql.com/
Description-en: MySQL database server (metapackage depending on the latest version)
This is an empty package that depends on the current "best" version of
mysql-server (currently mysql-server-5.7), as determined by the MySQL
maintainers. Install this package if in doubt about which MySQL
version you need. That will install the version recommended by the
package maintainers.
.
MySQL is a fast, stable and true multi-user, multi-threaded SQL database
server. SQL (Structured Query Language) is the most popular database query
language in the world. The main goals of MySQL are speed, robustness and
ease of use.
Description-md5: b8b44aa3bf1e86bb2834ded6d9d869b5
Task: lamp-server
Supported: 5y
开始安装
apt install mysql-server-5.7
#等待安装完成即可
#启动mysql服务
service mysql start
#开始安全配置向导
mysql_secure_installation
#开始时会让你配置root账户的密码
#注意每项的选择yes和no,其中以下项选no,因为要用到root远程登录,其他好像都是yes.
#Disallow root login remotely? [Y/n] n
2.配置mysql.
因为win10系统有些人已经装过mysql了,端口号要改下,还有其他的配置
网上说的在/etc/mysql/my.cnf修改,可能因为版本不同,我是在/etc/mysql/mysql.conf.d/mysqld.cnf
root@SC-201905211111:/opt# vim /etc/mysql/mysql.conf.d/mysqld.cnf
#内容我只拿了这要修改的部分:1.port改为3307 2.增加character-set-server=utf8
skip-grant-tables这两行,分别是设置字符编码和跳过登录时权限检查(不设置这个跳过权限,在navicat连接这个数据库时,就是被阻止)
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3307
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-server=utf8
skip-grant-tables
3.开启root远程访问权限
#重启mysql
service mysql restart
#登录mysql
mysql -uroot -p
#其中123456改成你的root用户的密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> flush privileges;
4.参照我的这边文章未wsl的mysql增加开机启动服务
https://www.jianshu.com/p/0a102c4bb3a2
root@SC-201905211111:/opt# vim /etc/init.wsl
#! /bin/sh
/etc/init.d/ssh $1
/etc/init.d/mysql $1
~
5.navicat连接,注意端口改为3307即可.