ubuntu20.04安装mysql5.7
安装之前要确保之前没安装过或者安装后卸载干净了,不然后面的配置文件可能会报错。
1. 下载安装包
打开链接 downloads.mysql.com/archives/co… 选择相应版本进行下载,这里mysql版本选择 5.7.35,系统选择Ubuntu Linux,选择64位的进行下载
2. 安装MySQL
-
将下载的包传入到Ubuntu中(或者在linux中使用wget工具下载完毕)
-
解压压缩包
tar -xvf mysql-server_5.7.35-1ubuntu18.04_amd64.deb-bundle.tar
解压完毕后,得到相应文件
-
安装mysql
# 先更新源 sudo apt-get update # 安装必要依赖 # 如果在安装 mysql-community-client 时提示 Package libtinfo5 is not installed,则应当执行下行命令 sudo apt-get install -y libtinfo5 # 如果在安装 mysql-community-server 时提示 Package libmecab2 is not installed,则应当执行以下命令 sudo apt-get install -y libmecab2 sudo apt-get install -y libaio1 # 开始安装mysql相关依赖包 sudo dpkg -i mysql-common_5.7.35-1ubuntu18.04_amd64.deb sudo dpkg -i libmysqlclient20_5.7.35-1ubuntu18.04_amd64.deb sudo dpkg -i libmysqlclient-dev_5.7.35-1ubuntu18.04_amd64.deb sudo dpkg -i libmysqld-dev_5.7.35-1ubuntu18.04_amd64.deb sudo dpkg -i libmysqlclient20_5.7.35-1ubuntu18.04_amd64.deb sudo dpkg -i mysql-community-client_5.7.35-1ubuntu18.04_amd64.deb sudo dpkg -i mysql-client_5.7.35-1ubuntu18.04_amd64.deb # 在安装 mysql-community-server_5.7.35 过程中会要求输入数据库用户root的密码 sudo dpkg -i mysql-community-server_5.7.35-1ubuntu18.04_amd64.deb sudo dpkg -i mysql-server_5.7.35-1ubuntu18.04_amd64.deb 以上命令都执行完毕后,mysql就安装完成了
-
在安装 mysql-community-server 时要求输入密码的页面
3. MySQL相关配置
在ubuntu系统中,mysql默认配置文件位于 /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0
// 登陆数据库
mysql -u root -p
// 查看所有数据库
SHOW DATABASES;
// 创建数据库
CREATE DATABASE front_ops;
// 查看所有用户
SELECT User, Host FROM mysql.user;
// 在MySQL中为远程访问创建用户并授予适当的权限:
CREATE USER 'your_user'@'%' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database.* TO 'your_user'@'%';
FLUSH PRIVILEGES;
5. 卸载MySQL
-
先停止mysql服务
-
// 查看所有相关进程 ps auxf | grep mysql sudo kill -9 进程Id sudo apt-get remove --purge mysql-server mysql-client mysql-common sudo rm -rf /etc/mysql /var/lib/mysql sudo apt-get autoremove sudo apt-get autoclean sudo deluser mysql sudo delgroup mysql sudo apt-get update sudo apt update sudo ls -l /var/lib/dpkg/info | grep -i mysql-server sudo rm -r /var/lib/dpkg/info/mysql-server-5.7 sudo rm -r /var/lib/dpkg/info/mysql-server-5.7.* sudo apt-get remove --purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-* sudo rm -rf /etc/mysql /var/lib/mysql sudo rm -rf /etc/mysql/ /var/lib/mysql sudo apt-get autoremove --purge mysql-apt-config sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7* dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
ubuntu20.04卸载和安装MySQL_ubuntu20安装数据库失败,卸载-CSDN博客
-
Ubuntu20.04 安装和卸载MySQL8 - coderdogz - 博客园
-
ubuntu20.04卸载和安装MySQL_ubuntu20安装数据库失败,卸载-CSDN博客
-
Ubuntu笔记-auto remove_apt autoremove问题-CSDN博客
-
Ubuntu20.04彻底删除mysql,并重装mysql_ubuntu20.04卸载mysql-CSDN博客
8.0.40-0ubuntu0.20.04.1 500
500 http://hk.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
500 http://hk.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages
500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
500 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages
8.0.19-0ubuntu5 500
500 http://hk.archive.ubuntu.com/ubuntu focal/main amd64 Packages
500 http://hk.archive.ubuntu.com/ubuntu focal/main i386 Packages
5.7.42-1ubuntu18.04 500
500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
5.7.42-0ubuntu0.18.04.1 500
500 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu bionic-security/main i386 Packages
500 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu bionic-updates/main i386 Packages
5.7.21-1ubuntu1 500
500 http://mirrors.aliyun.com/ubuntu bionic/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu bionic/main i386 Packages
sudo apt install mysql-client=5.7.42-1ubuntu18.04
sudo apt install mysql-server=5.7.42-1ubuntu18.04
//卸载mysql
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo delgroup mysql
sudo apt-get update
sudo apt update
// 查看当前mysql状态
sudo systemctl status mysql
// 授权权限
sudo chown -R mysql:mysql /var/run/mysqld
// 启动mysql
sudo systemctl start mysql
// 停止mysql
sudo systemctl stop mysql
// 查看有哪些mysql相关的进程
ps auxf | grep mysql