检查删除原有的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.tar2、解压到指定目录下
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-bin4、安装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啥的。完了后就可以登录了。
按 Tab 键就会切换。
5、远程连接
首次登录 sudo mysql
使用远程连接工具报错
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码'; systemctl restart mysql # 重启mysql远程连接正常
如果报错 ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%',确认 root 用户的实际 host,再需要远程访问(创建 root@% 用户):
SELECT user, host FROM mysql.user WHERE user = 'root'; CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码'; # 创建 root@% 用户 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; #赋予全部权限 FLUSH PRIVILEGES;6、开机自启动
参考博客:Ubuntu/Linux安装JDK、Mysql、Redis、Rabbitmq、Nginx 并设置开机自启动_ubuntu service mysql start 自动启动-CSDN博客
在centos中开机自启动命令 systemctl enable mysqld 在buntu中是 systemctl enable mysql systemctl restart mysql # 重启 systemctl status mysql # 查看状态7、ubuntu22.04直接安装mysql
上面方式没安装成功,先删除
dpkg -l | grep -i mysql sudo dpkg --purge mysql-common #彻底删除冲突包mysql-commonsudo 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) : nosudo mysql # 直接登录mysql update user set host = '%' where user = 'root'; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxxxx'; FLUSH PRIVILEGES; systemctl restart mysql # 重启mysqltlenet ip 3306 不通
vim /etc/mysql/mysql.conf.d/mysqld.cnf bind-address =127.0.0.1前加入#注释掉 systemctl restart mysql # 重启mysql使用第三方工具可以连接数据库