ubuntu 上的mysql8.0完全卸载+安装+第一次修改密码手册

卸载

sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
dpkg --list|grep mysql
sudo apt-get remove dbconfig-mysql
sudo apt-get remove mysql-client
sudo apt-get remove mysql-client-5.7
sudo apt-get remove mysql-client-core-5.7
sudo apt-get autoremove mysql* --purge
dpkg --list|grep mysql
sudo apt-get remove php7.0-mysql
dpkg -l|grep ^rc|awk ‘{print$2}’|sudo xargs dpkg -P
dpkg --list|grep mysql

安装

#服务端
sudo apt install mysql-server-8.0
#客户端
sudo apt install libmysqlclient-dev
#设置密码
sudo mysql -uroot
mysql> use mysql;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
mysql>flush privileges;
mysql> quit;
#重启mysql
sudo systemctl restart mysql.service

常用命令

#启动
service mysqld start 
#停止
service mysqld stop 
#重启
service mysqld restart
#查看MySQL运行状态
systemctl status mysql.service

远程登录mysql设置

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

#bind-address = 127.0.0.1 IP改成0.0.0.0 或者指定可以连接的IP

#重启
sudo service mysql restart

#设置root可以远程

mysql -u root -p

use mysql;

select user, host from user;

#一般会显示下面这样
#+------------------+-----------+
#| user             | host      |
#+------------------+-----------+
#| debian-sys-maint | localhost |
#| mysql.infoschema | localhost |
#| mysql.session    | localhost |
#| mysql.sys        | localhost |
#| root             | localhost |
#+------------------+-----------+

#localhost 改成%
update user set host='%' where user='root';

quit;

sudo service mysql restart


防火墙设置

#查看状态(如果开着)
sudo ufw status


#关闭防火墙(可选)
sudo ufw disable
 
#添加一条规则让防火墙放行3306端口(推荐)
sudo ufw allow 3306

你可能感兴趣的:(ubuntu,mysql,linux)