Continuously updated…
preface
Recently I installed THE Windows Subsystem for Linux (WSL) in Win10. Since I often use mysql for nodeJS recently, I tried to install mysql for WSL(Ubuntu). Here is scene L:
Mysql installation
sudo apt install mysql-server mysql-client
Copy the code
Try to start MySQL after the installation is complete
sudo mysql
Copy the code
Then an error occurs
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'(2)Copy the code
Bring a problem to Google and be eager to find a solution.
What do we learn from the experience of predecessors, in the WSL, / var/run/mysqld/mysqld. The sock file does not exist.
Vim /etc/mysql.my.cnf
# # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # ! includedir /etc/mysql/conf.d/ ! includedir /etc/mysql/mysql.conf.d/Copy the code
Open mysqld. CNF in /etc/mysql.conf. d according to the above configuration
WSL mysqld. CNF contains only *[mysql]*, and lacks socket configuration information
So when you lift up the keyboard, it’s like, dada, type something
The bind - address = 127.0.0.1 socket = / var/run/mysqld/mysqld. The sockCopy the code
The sock file is successfully configured
Next, since there is no mysqld directory under /var/run in WSL, run the following command to add a directory
sudo mkdir -p /var/run/mysqld
sudo chown mysql /var/run/mysqld/
sudo service mysql restart
Copy the code
Then I restart mysql service, and when I thought I was done, MYSQL again gave me a bolt out of the blue
- Mysql failed to start: su: warning: Cannot change directory to/Nonexistent: No such file or directory
This error is usually caused by an unexpected shutdown of the mysql server
Solutions are as follows:
# Ubuntu
sudo service mysql stop
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start
Copy the code
# CentOS
sudo systemctl stop mysql.service
sudo usermod -d /var/lib/mysql/ mysql
sudo systemctl start mysql.service
Copy the code
So far, the problem is basically solved, the following still have mysql security detection problem, later in the update bar ~~
link
- Mysql > install mysql