安裝:mysql
sudo apt update sudo apt install mysql-server
安裝過程會須要輸入密碼。sql
登陸:less
mysql -u root -p
容許遠程登陸:ide
直接啓動,用別臺機器遠程登陸會有2003的錯誤,容許遠程登陸作了以下嘗試:3d
1)登陸以後,嘗試修改root的host爲%rest
show databases; use mysql; select user, host from user;
update user set host = "%" where user = "root";
因爲存在多個root user,致使更新並不成功。(若是僅有一個root user,這種方式能夠成功)code
2)更新權限:server
grant all privileges on *.* to "root"@"%" identified by "root" with grant option; flush privileges;
可是遠程訪問仍是報了2003的錯誤。blog
3)修改配置,重啓mysql:ip
找到mysql的配置文件/etc/mysql/my.cnf, 將"bind-address = 127.0.0.1"註釋掉
# # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. #bind-address = 127.0.0.1
重啓mysql服務
sudo service mysql restart
通過這麼多嘗試以後,終於能夠遠程登陸了!