0%

WSL安装并运行MySQL Server

安装

1
2
3
sudo apt-get install mysql-server
apt-get install mariadb-client
sudo apt-get install libmysqlclient-dev

默认配置

sudo service mysql start启动服务
然后执行ps -aux | grep mysql可以得到:

1
/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 --log-syslog=1 --log-syslog-facility=daemon --log-syslog-tag=

启动服务时可能会报错:No directory, logging in with HOME=/
需要设置一下权限,再重新启动:

1
2
3
sudo service mysql stop
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start

允许windows访问数据库

设置root账户密码并登录

1
2
mysqladmin -u root password root
mysql -u root -p

给予admin用户访问权限

1
2
3
4
mysql
grant all on *.* to [email protected]'%' identified by '123456' with grant option;
flush privileges;
exit;

执行sudo service mysql restart即可使用[email protected]登陆服务器

参考

Linux上安装MySQL及其基础配置