Ubuntu安装mysql5.7

由于镜像不包含以前的老版本了,所以要更新为阿里云的镜像(我尝试过,这个镜像截至目前2023/05/08是可以使用的)

备份镜像源:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.old

修改 source.list 文件

sudo vim /etc/apt/sources.list
#  阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

更新镜像源:

# 更新镜像源
sudo apt-get update

这里如果遇到下边问题:

GPG error: http://repo.mysql.com/apt/ubuntu focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29

解决方案:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8C718D3B5072E1F5

更新软件:

# 更新软件
sudo apt-get upgrade
# 执行下面安装命令

# 安装mysql5.7服务端
sudo apt-get install mysql-server-5.7

# 安装mysql5.7客户端
sudo apt-get install mysql-client-5.7

# 使用c/c++等语言操作mysql的动态链接库,如果不需要可不安装
sudo apt install libmysqlclient-dev

如果你在安装 MySQL 时没有设置 root 密码,则默认情况下 root 用户没有密码,可以直接使用以下命令登录 MySQL:

mysql -u root

如果你需要设置 root 密码,可以按照以下步骤操作:

  1. 以 root 用户身份登录 MySQL:
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
FLUSH PRIVILEGES;
  1. 退出 MySQL:
exit

此后,你可以使用以下命令登录 MySQL:

mysql -u root -p

输入你设置的密码即可登录。

你可能感兴趣的:(服务器,ubuntu,linux,运维)