How to install MySQL 8.0 to Ubuntu 18.04 LTS

本文详细介绍如何在Ubuntu16.04LTS系统中安装MySQL8.0,包括添加软件源、安装配置包、使用清华大学镜像加速、安装MySQL服务及客户端、创建数据库和用户权限设置等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天给大家介绍一下如何在Ubuntu 16.04 LTS中安装mysql 8.0。

Add repository of apt

Download deb mysql-apt-config

MySQL官方将MySQL软件源APT Repository配置制作成了mysql-apt-config_x.y-z_all.deb,所以我们这里下载并安装mysql-apt-config_0.8.13-1_all.deb以便添加软件源。

lwk@qwfys ~/Downloads/.tmp $ wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb
--2018-06-04 23:12:13--  https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb [following]
--2018-06-04 23:12:22--  https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb
Resolving repo.mysql.com (repo.mysql.com)... 23.219.134.205
Connecting to repo.mysql.com (repo.mysql.com)|23.219.134.205|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 35970 (35K) [application/x-debian-package]
Saving to: ‘mysql-apt-config_0.8.13-1_all.deb’

mysql-apt-config_0.8.13-1_all.deb                           100%[=========================================================================================================================================>]  35.13K  --.-KB/s    in 0.06s   

2018-06-04 23:12:22 (628 KB/s) - ‘mysql-apt-config_0.8.13-1_all.deb’ saved [35970/35970]

Install mysql-apt-config deb

这里用dpkg -i命令安装该.deb软件包:

lwk@qwfys ~/Downloads/.tmp $ sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb
(Reading database ... 301807 files and directories currently installed.)
Preparing to unpack mysql-apt-config_0.8.13-1_all.deb ...
Unpacking mysql-apt-config (0.8.10-1) over (0.8.10-1) ...
Setting up mysql-apt-config (0.8.10-1) ...
OK
lwk@qwfys ~/Downloads/.tmp $

添加软件源的过程中,会弹出如下对话框,选择"OK",即可。
mysql-apt-config

mysql-apt-config作用分析

至此,软件源配置已经完成,这时会在目录/etc/apt/sources.list.d/中生成文件mysql.list

lwk@qwfys ~ $ cat /etc/apt/sources.list.d/mysql.list 
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out entries below, but any other modifications may be lost.
# Use command 'dpkg-reconfigure mysql-apt-config' as root for modifications.
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-apt-config
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-8.0
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools
#deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools-preview
deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-8.0
lwk@qwfys ~ $ 

其实,mysql-apt-config的作用,主要有:
(1)为我们导入mysql deb包软件源的key。

sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5

(2)为我们生成上面的mysql.list软件源文件。

With tsinghua’s mirrors

如果国内更新网速比较慢时,也可以用国内镜像源来替换mysql.list文件中的内容。这里,我们用清华大学开源镜像站mysql deb软件源来更换上mysql.list中的内容。

sudo tee /etc/apt/sources.list.d/mysql.list <<-'EOF'
# Use command 'dpkg-reconfigure mysql-apt-config' as root for modifications.
deb [arch=amd64] http://mirrors.tuna.tsinghua.edu.cn/mysql/apt/ubuntu bionic mysql-apt-config
deb [arch=amd64] http://mirrors.tuna.tsinghua.edu.cn/mysql/apt/ubuntu bionic mysql-8.0
deb [arch=amd64] http://mirrors.tuna.tsinghua.edu.cn/mysql/apt/ubuntu bionic mysql-tools
deb [arch=amd64] http://mirrors.tuna.tsinghua.edu.cn/mysql/apt/ubuntu bionic mysql-tools-preview
EOF

Update deg package index

更新本地apt软件包缓存以便 进一步安装:

apt update

Install deb package with apt

用如下命令安装

apt install -y mysql-server mysql-client mysql-workbench-community

我们看到,MySQL8.0 服务已经启动,运行状态良好。

在安装过程中,会依次出现输入密码、确认密码、账户安装模式选择三个对话框,如下所示。

这里写图片描述
初始密码
这里写图片描述
确认密码
这里写图片描述
账户安全模式

Connect to the Server

MSQL客户端很多,为了方便起见,这里我们使用命令行客户端工具,示例如下:

lwk@qwfys:~$ sudo mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.17 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 

Create database

mysql> create database lwk;
Query OK, 1 row affected (0.01 sec)

mysql> use lwk;
Database changed
mysql> 

User & Privileges

mysql> CREATE USER 'lwk'@'%' IDENTIFIED WITH mysql_native_password BY '4F763CCD7253D8C1794D';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'lwk'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
lwk@qwfys:~$

重新登录

lwk@qwfys:~$ mysql -u lwk -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.17 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lwk                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> 

Uninstall

apt purge -y mysql-client mysql-server mysql-workbench-community

uninstall mysql 8.0

Use mysql workbench

在这里插入图片描述
在这里插入图片描述

Reference

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qwfys200

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值