检查删除原有的mysql(可以不做,自己记录)
1、 下载
MySQL :: Download MySQL Community Server (Archived Versions)
wget https://cdn.mysql.com/archives/mysql-8.0/mysql-server_8.0.32-1ubuntu20.04_amd64.deb-bundle.tar
2、解压到指定目录下
tar xvf mysql-server_8.0.32-1ubuntu20.04_amd64.deb-bundle.tar -C /opt/mysql-8.0.32/
3、安装依赖
sudo apt install -y libaio1 libmecab2 man-db libc-bin
4、安装mysql
dpkg -i mysql-community-client-plugins_8.0.32-1ubuntu20.04_amd64.deb
dpkg -i mysql-community-client-core_8.0.32-1ubuntu20.04_amd64.deb
dpkg -i mysql-common_8.0.32-1ubuntu20.04_amd64.deb
dpkg -i mysql-community-client_8.0.32-1ubuntu20.04_amd64.deb
dpkg -i mysql-client_8.0.32-1ubuntu20.04_amd64.deb
dpkg -i mysql-community-server-core_8.0.32-1ubuntu20.04_amd64.deb
dpkg -i mysql-community-server_8.0.32-1ubuntu20.04_amd64.deb
确认完密码后,有个选项,我选的第一个,第二个好像是mysql5啥的。完了后就可以登录了。
5、远程连接
使用远程连接工具报错
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
systemctl restart mysql # 重启mysql
远程连接正常
6、开机自启动
参考博客:Ubuntu/Linux安装JDK、Mysql、Redis、Rabbitmq、Nginx 并设置开机自启动_ubuntu service mysql start 自动启动-优快云博客
在centos中开机自启动命令 systemctl enable mysqld
在buntu中是 systemctl enable mysql
systemctl restart mysql # 重启
systemctl status mysql # 查看状态
7、ubuntu22.04直接安装mysql
sudo apt update
sudo apt install mysql-server
systemctl status mysql # 可以看到mysql已经启动成功
# 执行安全初始化脚本以增强安全性(例如:禁用匿名用户、删除测试数据库等)
sudo mysql_secure_installation
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : no
sudo mysql # 直接登录mysql
update user set host = '%' where user = 'root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxxxx';
FLUSH PRIVILEGES;
systemctl restart mysql # 重启mysql
tlenet ip 3306 不通
vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address =127.0.0.1前加入#注释掉
systemctl restart mysql # 重启mysql
使用第三方工具可以连接数据库