查看本机安装MySQL

dpkg -l | grep mysql

卸载本机MySQL

sudo apt-get autoremove --purge mysql-server-5.7
sudo apt-get remove mysql-server
sudo apt-get autoremove mysql-server
sudo apt-get remove mysql-common
sudo apt remove mysql-client-core-5.7
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

安装MySQL

sudo apt-get install mysql-server
sudo apt-get install mysql-client

查看MySQL是否正在运行

sudo netstat -tap | grep mysql

MySQL开启关闭重启

sudo service mysql stop
sudo service mysql start
sudo service mysql restart

查看默认密码

sudo cat /etc/mysql/debian.cnf

使用默认user和passwd登录

mysql -udebian-sys-maint -ppasswd

修改密码

show databases;
use mysql;
update user set authentication_string=PASSWORD("12345") where user='root';
update user set plugin="mysql_native_password";
flush privileges;
exit;

远程登录MySQL权限开启

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
flush privileges;
exit;

编辑配置文件

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 注释掉这一行
# bind-address        = 127.0.0.1

重启MySQL

sudo service mysql restart