ubuntu24.04安装MySQL数据库
在新系统ubuntu24.04安装MySQL数据库,有2种不同的方式安装mysql数据库,安装的版本页不一样。
第一种,安装默认版本,我这里默认的是8.0.46 版本
sudo apt update
sudo apt upgrade -y
#安装依赖
sudo apt install wget gnupg lsb-release -y
# 安装服务
apt install mysql-server -y
# 启动并设置开机自启
sudo systemctl start mysql
sudo systemctl enable mysql
# 安装完毕后,默认没有数据库初始化,需要初始化
sudo mysql_secure_installation
第二种,安装指定版本的
cat /etc/apt/sources.list.d/mysql.list
deb http://repo.mysql.com/apt/ubuntu/ noble mysql-8.0
# 更改为mysql-8.4-lts 即最新版
# 编辑上面文件更改为 deb http://repo.mysql.com/apt/ubuntu/ noble mysql-8.4-lts
# 更新源
sudo apt clean
sudo apt update
# 查看结果
apt-cache policy mysql-server
mysql-server:
Candidate: 8.4.10-1ubuntu24.04
# 如果不是新版本
sudo apt clean
sudo rm -rf /var/lib/apt/lists/*
sudo apt update
# 再次查看
apt-cache policy mysql-server
# 或者强制安装指定
sudo apt install mysql-server=8.4.10-1ubuntu24.04
如升级过程中出现
W: GPG error: http://repo.mysql.com/apt/ubuntu noble InRelease: The following signatures were invalid: EXPKEYSIG
参考:W: GPG error: http://repo.mysql.com/apt/ubuntu noble InRelease: The following signatures were invalid: EXPKEYSIG