Ubuntu系统下使用apt-get安装Mysql8

记录一下在Ubuntu20.04 64位系统下面使用apt-get方式安装mysql8关系型数据库

Centos下使用yum安装Mysql8(Mysql5.7)以及常见的配置和使用

首先肯定是检查下当前Ubuntu系统是否已经安装过mysql数据库 一般拿到新的云服务器是没有安装的

root@myw:~# whereis mysql
mysql:
root@myw:~# find / -name 'mysql*'
/etc/apparmor.d/abstractions/mysql
/usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/mysql.cpython-38.pyc
/usr/lib/python3/dist-packages/sos/report/plugins/mysql.py
/usr/share/bash-completion/completions/mysqladmin
/usr/share/bash-completion/completions/mysql
/usr/share/vim/vim81/syntax/mysql.vim
root@myw:~# 

Ubuntu系统和centos所用的依赖包管理器不一样
Ubuntu用的是apt包管理器 centos用的是yum包管理器

那么这里使用apt-get来安装mysql 为了能够安装高版本的mysql 我这里首先是更新apt-get 更新之后去安装mysql 发现mysql安装好后是8.x版本 对于使用8.x版本来说,这是一个很欣喜的消息

更新apt-get系统软件库

apt-get update
root@myw:~# apt-get update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease   
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [2,464 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,850 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [385 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [13.2 kB]      
Get:9 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [2,210 kB]        
Get:10 http://security.ubuntu.com/ubuntu focal-security/restricted Translation-en [309 kB]          
Get:11 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 c-n-f Metadata [580 B]  
Get:12 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [885 kB]    
Get:13 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [185 kB]
Get:14 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [19.1 kB]
Get:15 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [23.6 kB]   
Get:16 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [5,504 B]                            
Get:17 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [548 B]
Get:18 http://archive.ubuntu.com/ubuntu focal-updates/main Translation-en [468 kB]
Get:19 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [17.1 kB]
Get:20 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [2,327 kB]
Get:21 http://archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [325 kB]
Get:22 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [576 B]
Get:23 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1,117 kB]
Get:24 http://archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [267 kB]
Get:25 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [25.6 kB]
Get:26 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [25.8 kB]
Get:27 http://archive.ubuntu.com/ubuntu focal-updates/multiverse Translation-en [7,484 B]
Get:28 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [620 B]
Get:29 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [45.7 kB]
Get:30 http://archive.ubuntu.com/ubuntu focal-backports/main Translation-en [16.3 kB]
Get:31 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 c-n-f Metadata [1,420 B]
Get:32 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [25.0 kB]
Get:33 http://archive.ubuntu.com/ubuntu focal-backports/universe Translation-en [16.3 kB]                                                                               
Get:34 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [880 B]                                                                           
Fetched 14.4 MB in 6s (2,221 kB/s)                                                                                                                                                                                                                          
Reading package lists... Done
root@myw:~# 

直接安装mysql

apt-get install mysql-server -y
root@myw:~# apt-get install mysql-server -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0
Suggested packages:
  libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca
The following NEW packages will be installed:
  libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0
0 upgraded, 25 newly installed, 0 to remove and 271 not upgraded.
Need to get 36.7 MB of archives.
After this operation, 318 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 mysql-common all 5.8+1.0.5ubuntu2 [7,496 B]
Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client-core-8.0 amd64 8.0.34-0ubuntu0.20.04.1 [5,075 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client-8.0 amd64 8.0.34-0ubuntu0.20.04.1 [22.0 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal/main amd64 libevent-core-2.1-7 amd64 2.1.11-stable-1 [89.1 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal/main amd64 libevent-pthreads-2.1-7 amd64 2.1.11-stable-1 [7,372 B]
Get:6 http://archive.ubuntu.com/ubuntu focal/main amd64 libmecab2 amd64 0.996-10build1 [233 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server-core-8.0 amd64 8.0.34-0ubuntu0.20.04.1 [22.6 MB]
Get:8 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server-8.0 amd64 8.0.34-0ubuntu0.20.04.1 [1,325 kB]
Get:9 http://archive.ubuntu.com/ubuntu focal/main amd64 libhtml-tagset-perl all 3.20-4 [12.5 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/main amd64 liburi-perl all 1.76-2 [77.5 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/main amd64 libhtml-parser-perl amd64 3.72-5 [86.3 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal/main amd64 libcgi-pm-perl all 4.46-1 [186 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal/main amd64 libfcgi-perl amd64 0.79-1 [33.1 kB]                                                                                                                                                                
Get:14 http://archive.ubuntu.com/ubuntu focal/main amd64 libcgi-fast-perl all 1:2.15-1 [10.5 kB]                                                                                                                                                            
Get:15 http://archive.ubuntu.com/ubuntu focal/main amd64 libencode-locale-perl all 1.05-1 [12.3 kB]                                                                                                                                                         
Get:16 http://archive.ubuntu.com/ubuntu focal/main amd64 libhtml-template-perl all 2.97-1 [59.0 kB]                                                                                                                                                         
Get:17 http://archive.ubuntu.com/ubuntu focal/main amd64 libtimedate-perl all 2.3200-1 [34.0 kB]                                                                                                                                                            
Get:18 http://archive.ubuntu.com/ubuntu focal/main amd64 libhttp-date-perl all 6.05-1 [9,920 B]                                                                                                                                                             
Get:19 http://archive.ubuntu.com/ubuntu focal/main amd64 libio-html-perl all 1.001-1 [14.9 kB]                                                                                                                                                              
Get:20 http://archive.ubuntu.com/ubuntu focal/main amd64 liblwp-mediatypes-perl all 6.04-1 [19.5 kB]                                                                                                                                                        
Get:21 http://archive.ubuntu.com/ubuntu focal/main amd64 libhttp-message-perl all 6.22-1 [76.1 kB]                                                                                                                                                          
Get:22 http://archive.ubuntu.com/ubuntu focal/main amd64 mecab-utils amd64 0.996-10build1 [4,912 B]                                                                                                                                                         
Get:23 http://archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic all 2.7.0-20070801+main-2.1 [6,714 kB]                                                                                                                                                
Get:24 http://archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic-utf8 all 2.7.0-20070801+main-2.1 [4,380 B]                                                                                                                                            
Get:25 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server all 8.0.34-0ubuntu0.20.04.1 [9,468 B]                                                                                                                                         
Fetched 36.7 MB in 12s (3,130 kB/s)                                                                                                                                                                                                                         
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 72145 files and directories currently installed.)
Preparing to unpack .../0-mysql-common_5.8+1.0.5ubuntu2_all.deb ...
Unpacking mysql-common (5.8+1.0.5ubuntu2) ...
Selecting previously unselected package mysql-client-core-8.0.
Preparing to unpack .../1-mysql-client-core-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb ...
Unpacking mysql-client-core-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Selecting previously unselected package mysql-client-8.0.
Preparing to unpack .../2-mysql-client-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb ...
Unpacking mysql-client-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Selecting previously unselected package libevent-core-2.1-7:amd64.
Preparing to unpack .../3-libevent-core-2.1-7_2.1.11-stable-1_amd64.deb ...
Unpacking libevent-core-2.1-7:amd64 (2.1.11-stable-1) ...
Selecting previously unselected package libevent-pthreads-2.1-7:amd64.
Preparing to unpack .../4-libevent-pthreads-2.1-7_2.1.11-stable-1_amd64.deb ...
Unpacking libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ...
Selecting previously unselected package libmecab2:amd64.
Preparing to unpack .../5-libmecab2_0.996-10build1_amd64.deb ...
Unpacking libmecab2:amd64 (0.996-10build1) ...
Selecting previously unselected package mysql-server-core-8.0.
Preparing to unpack .../6-mysql-server-core-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb ...
Unpacking mysql-server-core-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Setting up mysql-common (5.8+1.0.5ubuntu2) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Selecting previously unselected package mysql-server-8.0.
(Reading database ... 72361 files and directories currently installed.)
Preparing to unpack .../00-mysql-server-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb ...
Unpacking mysql-server-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Selecting previously unselected package libhtml-tagset-perl.
Preparing to unpack .../01-libhtml-tagset-perl_3.20-4_all.deb ...
Unpacking libhtml-tagset-perl (3.20-4) ...
Selecting previously unselected package liburi-perl.
Preparing to unpack .../02-liburi-perl_1.76-2_all.deb ...
Unpacking liburi-perl (1.76-2) ...
Selecting previously unselected package libhtml-parser-perl.
Preparing to unpack .../03-libhtml-parser-perl_3.72-5_amd64.deb ...
Unpacking libhtml-parser-perl (3.72-5) ...
Selecting previously unselected package libcgi-pm-perl.
Preparing to unpack .../04-libcgi-pm-perl_4.46-1_all.deb ...
Unpacking libcgi-pm-perl (4.46-1) ...
Selecting previously unselected package libfcgi-perl.
Preparing to unpack .../05-libfcgi-perl_0.79-1_amd64.deb ...
Unpacking libfcgi-perl (0.79-1) ...
Selecting previously unselected package libcgi-fast-perl.
Preparing to unpack .../06-libcgi-fast-perl_1%3a2.15-1_all.deb ...
Unpacking libcgi-fast-perl (1:2.15-1) ...
Selecting previously unselected package libencode-locale-perl.
Preparing to unpack .../07-libencode-locale-perl_1.05-1_all.deb ...
Unpacking libencode-locale-perl (1.05-1) ...
Selecting previously unselected package libhtml-template-perl.
Preparing to unpack .../08-libhtml-template-perl_2.97-1_all.deb ...
Unpacking libhtml-template-perl (2.97-1) ...
Selecting previously unselected package libtimedate-perl.
Preparing to unpack .../09-libtimedate-perl_2.3200-1_all.deb ...
Unpacking libtimedate-perl (2.3200-1) ...
Selecting previously unselected package libhttp-date-perl.
Preparing to unpack .../10-libhttp-date-perl_6.05-1_all.deb ...
Unpacking libhttp-date-perl (6.05-1) ...
Selecting previously unselected package libio-html-perl.
Preparing to unpack .../11-libio-html-perl_1.001-1_all.deb ...
Unpacking libio-html-perl (1.001-1) ...
Selecting previously unselected package liblwp-mediatypes-perl.
Preparing to unpack .../12-liblwp-mediatypes-perl_6.04-1_all.deb ...
Unpacking liblwp-mediatypes-perl (6.04-1) ...
Selecting previously unselected package libhttp-message-perl.
Preparing to unpack .../13-libhttp-message-perl_6.22-1_all.deb ...
Unpacking libhttp-message-perl (6.22-1) ...
Selecting previously unselected package mecab-utils.
Preparing to unpack .../14-mecab-utils_0.996-10build1_amd64.deb ...
Unpacking mecab-utils (0.996-10build1) ...
Selecting previously unselected package mecab-ipadic.
Preparing to unpack .../15-mecab-ipadic_2.7.0-20070801+main-2.1_all.deb ...
Unpacking mecab-ipadic (2.7.0-20070801+main-2.1) ...
Selecting previously unselected package mecab-ipadic-utf8.
Preparing to unpack .../16-mecab-ipadic-utf8_2.7.0-20070801+main-2.1_all.deb ...
Unpacking mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../17-mysql-server_8.0.34-0ubuntu0.20.04.1_all.deb ...
Unpacking mysql-server (8.0.34-0ubuntu0.20.04.1) ...
Setting up libmecab2:amd64 (0.996-10build1) ...
Setting up mysql-client-core-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Setting up libhtml-tagset-perl (3.20-4) ...
Setting up liblwp-mediatypes-perl (6.04-1) ...
Setting up libencode-locale-perl (1.05-1) ...
Setting up mecab-utils (0.996-10build1) ...
Setting up libevent-core-2.1-7:amd64 (2.1.11-stable-1) ...
Setting up libio-html-perl (1.001-1) ...
Setting up libtimedate-perl (2.3200-1) ...
Setting up mysql-client-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Setting up libfcgi-perl (0.79-1) ...
Setting up liburi-perl (1.76-2) ...
Setting up libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ...
Setting up libhttp-date-perl (6.05-1) ...
Setting up mecab-ipadic (2.7.0-20070801+main-2.1) ...
Compiling IPA dictionary for Mecab.  This takes long time...
reading /usr/share/mecab/dic/ipadic/unk.def ... 40
emitting double-array: 100% |###########################################| 
/usr/share/mecab/dic/ipadic/model.def is not found. skipped.
reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120
reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91
reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42
reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210
reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146
reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328
reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171
reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199
reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032
reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151
reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393
reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135
reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19
reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999
reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221
reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208
reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795
reading /usr/share/mecab/dic/ipadic/Others.csv ... 2
reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202
reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328
reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252
reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668
reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750
reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42
reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146
reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477
emitting double-array: 100% |###########################################| 
reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316
emitting matrix      : 100% |###########################################| 

done!
update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
Setting up mysql-server-core-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Setting up mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ...
Compiling IPA dictionary for Mecab.  This takes long time...
reading /usr/share/mecab/dic/ipadic/unk.def ... 40
emitting double-array: 100% |###########################################| 
/usr/share/mecab/dic/ipadic/model.def is not found. skipped.
reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120
reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91
reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42
reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210
reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146
reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328
reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171
reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199
reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032
reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151
reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393
reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135
reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19
reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999
reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221
reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208
reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795
reading /usr/share/mecab/dic/ipadic/Others.csv ... 2
reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202
reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328
reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252
reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668
reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750
reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42
reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146
reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477
emitting double-array: 100% |###########################################| 
reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316
emitting matrix      : 100% |###########################################| 

done!
update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
Setting up libhtml-parser-perl (3.72-5) ...
Setting up libhttp-message-perl (6.22-1) ...
Setting up mysql-server-8.0 (8.0.34-0ubuntu0.20.04.1) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 19288
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
insserv: warning: script 'S03denyhosts' missing LSB tags and overrides
insserv: warning: script 'denyhosts' missing LSB tags and overrides
Setting up libcgi-pm-perl (4.46-1) ...
Setting up libhtml-template-perl (2.97-1) ...
Setting up mysql-server (8.0.34-0ubuntu0.20.04.1) ...
Setting up libcgi-fast-perl (1:2.15-1) ...
Processing triggers for systemd (245.4-4ubuntu3.5) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
root@myw:~# 

从执行指令安装的这些信息来看 默认安装mysql后 默认是启动的,看这条信息

mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 19288

这是一条很欣喜的是消息,首先来确认下mysql的版本 8.0.x

root@myw:~# mysql -V
mysql  Ver 8.0.34-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
root@myw:~# mysql --version
mysql  Ver 8.0.34-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
root@myw:~# 

确认下mysql是否启动 在这里使用指令发现缺少工具,那么使用apt安装一下便可以

root@myw:~# netstat -lnp|grep 3306

Command 'netstat' not found, but can be installed with:

apt install net-tools

root@myw:~# 

执行

root@myw:~# apt-get install net-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 271 not upgraded.
Need to get 196 kB of archives.
After this operation, 864 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB]
Fetched 196 kB in 2s (110 kB/s)     
Selecting previously unselected package net-tools.
(Reading database ... 72727 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...
root@myw:~# 

确认mysql是否运行

root@myw:~# netstat -lnp|grep 3306
tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN      19601/mysqld        
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      19601/mysqld        
root@myw:~# netstat -lnp|grep mysql
tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN      19601/mysqld        
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      19601/mysqld        
unix  2      [ ACC ]     STREAM     LISTENING     163194   19601/mysqld         /var/run/mysqld/mysqlx.sock
unix  2      [ ACC ]     STREAM     LISTENING     162394   19601/mysqld         /var/run/mysqld/mysqld.sock
root@myw:~# netstat -lnp|grep mysqld
tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN      19601/mysqld        
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      19601/mysqld        
unix  2      [ ACC ]     STREAM     LISTENING     163194   19601/mysqld         /var/run/mysqld/mysqlx.sock
unix  2      [ ACC ]     STREAM     LISTENING     162394   19601/mysqld         /var/run/mysqld/mysqld.sock
root@myw:~# 

进入mysql内可以直接使用mysql指令进去,不需要密码

root@myw:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.34-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> \s
--------------
mysql  Ver 8.0.34-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

Connection id:          8
Current database:       
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         8.0.34-0ubuntu0.20.04.1 (Ubuntu)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /var/run/mysqld/mysqld.sock
Binary data as:         Hexadecimal
Uptime:                 4 min 33 sec

Threads: 2  Questions: 5  Slow queries: 0  Opens: 119  Flush tables: 3  Open tables: 38  Queries per second avg: 0.018
--------------

mysql> 

也可以使用root来登录 root用户不需要输入密码的

root@myw:~# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.34-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> 

查看mysql内的用户信息,发现其中有一条数据User是debian-sys-maint 这条直接删掉

mysql> use mysql
Database changed
mysql> select Host, User, plugin, authentication_string, password_lifetime from user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+-------------------+
| Host      | User             | plugin                | authentication_string                                                  | password_lifetime |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+-------------------+
| localhost | debian-sys-maint | caching_sha2_password | $A$005$
^2lO) KVuHJ5LuXU8r1FPmt5.KJA.LCBgue/SrC42rvBmqDmSv3 |              NULL |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |              NULL |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |              NULL |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |              NULL |
| localhost | root             | auth_socket           |                                                                        |              NULL |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+-------------------+
5 rows in set (0.01 sec)

mysql> delete from user where user='debian-sys-maint';
Query OK, 1 row affected (0.00 sec)

mysql> select host,user,plugin,authentication_string, password_lifetime from user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+-------------------+
| host      | user             | plugin                | authentication_string                                                  | password_lifetime |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+-------------------+
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |              NULL |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |              NULL |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |              NULL |
| localhost | root             | auth_socket           |                                                                        |              NULL |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+-------------------+
4 rows in set (0.00 sec)

mysql> 


数据库执行初始化

安装好mysql数据库后,本身就可以使用了,也可以执行一次初始化(在数据库运行时才能执行)

mysql_secure_installation

是否启用密码有效验证插件

root@myw:~# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

//	是否启用密码有效验证插件 必须选择是 y
Press y|Y for Yes, any other key for No: y

设置密码强度复杂度

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

//	设置密码强度复杂度 中级 八位 数字 大小写字母 特殊字符
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

移除匿名用户

Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

//	移除匿名用户
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

是否允许远程登录

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
//	是否允许远程登录
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

删除测试数据库


 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

//	删除测试数据库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.
 - Removing privileges on test database...
Success.

重新刷新权限


Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
重新刷新权限
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
root@myw:~# 

mysql数据安装好 默认加入了开机启动的 因此也不需要担心服务器重启

mysql 常用的 开 关 重启 取消开机启动指令

 
// 启动
systemctl start mysql
 
// 重启
systemctl restart mysql
 
// 停止
systemctl stop mysql
 
// 查看启动状态
systemctl status mysql
 
// 加入开机启动
systemctl enable mysql
 
// 取消开机启动
systemctl disable mysql

通过创建一个数据库方式 再去找这个数据库的名字就能找到mysql默认存数据的位置
Ubuntu系统下使用apt-get安装Mysql8_第1张图片
在centos系统中/etc/my.cnf里配置mysql的参数 但是在Ubuntu系统有些不同,在Ubuntu系统的/etc下面是找不到my.cnf配置文件的,但是可以找到一个mysql的文件夹
Ubuntu系统下使用apt-get安装Mysql8_第2张图片
打开my.cnf文件 里面的内容如下 mysql.cnf里也差不多的
Ubuntu系统下使用apt-get安装Mysql8_第3张图片
一般情况下配置编码 但在mysql8里默认编码就可以utf8mb4,所以其他参数在简单应用里不需要调整的,有一个点需要注意,mysql8默认是打开了binlog日志存储的,如果稍微数据量大,那么会产生大量的日志文件(在/var/lib/mysql下面存在,binlog.index, binlog.0000xx这类很大的文件),云服务器的云盘太少,很容易爆满的,因此一般应用需要把它关掉

可以先去查看

mysql> SHOW VARIABLES LIKE 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set (0.00 sec)

mysql> 

ON是开启的,关掉需要配置
先找到mysqld.cnf文件
Ubuntu系统下使用apt-get安装Mysql8_第4张图片
打开后的文件内容

#
# The MySQL database server configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld]
#
# * Basic Settings
#
user		= mysql
# pid-file	= /var/run/mysqld/mysqld.pid
# socket	= /var/run/mysqld/mysqld.sock
# port		= 3306
# datadir	= /var/lib/mysql


# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir		= /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address		= 127.0.0.1
mysqlx-bind-address	= 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size		= 16M
# max_allowed_packet	= 64M
# thread_stack		= 256K

# thread_cache_size       = -1

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP

# max_connections        = 151

# table_open_cache       = 4000

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
# general_log_file        = /var/log/mysql/query.log
# general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
# slow_query_log		= 1
# slow_query_log_file	= /var/log/mysql/mysql-slow.log
# long_query_time = 2
# log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
# server-id		= 1
# log_bin			= /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds	= 2592000
max_binlog_size   = 100M
# binlog_do_db		= include_database_name
# binlog_ignore_db	= include_database_name

在这个文件的末尾加上配置

disable-log-bin

或者

skip-log-bin

Ubuntu系统下使用apt-get安装Mysql8_第5张图片
再执行指令

mysql> SHOW VARIABLES LIKE 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | OFF   |
+---------------+-------+
1 row in set (0.00 sec)

mysql> 

可以看到biglog已经关掉了

在查询指令可以看到更多信息

show variables like "%bin%";
mysql> show variables like "%bin%";
+------------------------------------------------+----------------------+
| Variable_name                                  | Value                |
+------------------------------------------------+----------------------+
| bind_address                                   | 127.0.0.1            |
| binlog_cache_size                              | 32768                |
| binlog_checksum                                | CRC32                |
| binlog_direct_non_transactional_updates        | OFF                  |
| binlog_encryption                              | OFF                  |
| binlog_error_action                            | ABORT_SERVER         |
| binlog_expire_logs_auto_purge                  | ON                   |
| binlog_expire_logs_seconds                     | 2592000              |
| binlog_format                                  | ROW                  |
| binlog_group_commit_sync_delay                 | 0                    |
| binlog_group_commit_sync_no_delay_count        | 0                    |
| binlog_gtid_simple_recovery                    | ON                   |
| binlog_max_flush_queue_time                    | 0                    |
| binlog_order_commits                           | ON                   |
| binlog_rotate_encryption_master_key_at_startup | OFF                  |
| binlog_row_event_max_size                      | 8192                 |
| binlog_row_image                               | FULL                 |
| binlog_row_metadata                            | MINIMAL              |
| binlog_row_value_options                       |                      |
| binlog_rows_query_log_events                   | OFF                  |
| binlog_stmt_cache_size                         | 32768                |
| binlog_transaction_compression                 | OFF                  |
| binlog_transaction_compression_level_zstd      | 3                    |
| binlog_transaction_dependency_history_size     | 25000                |
| binlog_transaction_dependency_tracking         | COMMIT_ORDER         |
| innodb_api_enable_binlog                       | OFF                  |
| log_bin                                        | OFF                  |
| log_bin_basename                               |                      |
| log_bin_index                                  |                      |
| log_bin_trust_function_creators                | OFF                  |
| log_bin_use_v1_row_events                      | OFF                  |
| log_statements_unsafe_for_binlog               | ON                   |
| max_binlog_cache_size                          | 18446744073709547520 |
| max_binlog_size                                | 104857600            |
| max_binlog_stmt_cache_size                     | 18446744073709547520 |
| mysqlx_bind_address                            | 127.0.0.1            |
| sql_log_bin                                    | ON                   |
| sync_binlog                                    | 1                    |
+------------------------------------------------+----------------------+
38 rows in set (0.00 sec)

mysql> 

远程路由连接mysql

mysql安装在云端 要在本地通过一些远程连接工具来连接云端的mysql 需要创建能够远程连接的账号

mysql>  CREATE USER 'myroot'@'%' IDENTIFIED BY 'myW.123456';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL ON *.* TO 'myroot'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select Host, User, plugin, authentication_string, password_lifetime, password_last_changed from user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+-------------------+-----------------------+
| Host      | User             | plugin                | authentication_string                                                  | password_lifetime | password_last_changed |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+-------------------+-----------------------+
| %         | myroot           | caching_sha2_password | $A$005$^`=S'1HhJ|hR/^,9,iVqqzJ3IKSfy7BMFtllgWqDvbSm5U76E84OVTJXWQZUtF. |              NULL | 2023-09-21 14:18:21   |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |              NULL | 2023-09-21 12:40:28   |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |              NULL | 2023-09-21 12:40:28   |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |              NULL | 2023-09-21 12:40:28   |
| localhost | root             | auth_socket           |                                                                        |              NULL | 2023-09-21 12:40:28   |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+-------------------+-----------------------+
5 rows in set (0.00 sec)

mysql> 

可以看到我在这里创建了一个myroot用户 密码是myW.123456 是满足远程连接的
使用navicat(15版本以上支持mysql8的效果更好)
Ubuntu系统下使用apt-get安装Mysql8_第6张图片
可以看到连接不上,
在centos下安装的mysql8 只要账号满足就可以自我本地电脑远程连接,但是在Ubuntu下还需要改刚才的那个配置文件

目录下面

/etc/mysql/mysql.conf.d/mysqld.cnf

bind-address		= 127.0.0.1

改成

bind-address		= 0.0.0.0

myw
修改后必须重启mysql 不重启不生效的
然后访问
Ubuntu系统下使用apt-get安装Mysql8_第7张图片

再来看在Ubuntu系统里关于mysql的信息和路径

root@myw:~# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
root@myw:~# find / -name 'mysql*'
/etc/init/mysql.conf
/etc/logrotate.d/mysql-server
/etc/apparmor.d/abstractions/mysql
/etc/mysql
/etc/mysql/mysql.cnf
/etc/mysql/conf.d/mysql.cnf
/etc/mysql/conf.d/mysqldump.cnf
/etc/mysql/mysql.conf.d
/etc/mysql/mysql.conf.d/mysql.cnf
/etc/mysql/mysql.conf.d/mysqld.cnf
/etc/init.d/mysql
/etc/logcheck/ignore.d.workstation/mysql-server-8_0
/etc/logcheck/ignore.d.server/mysql-server-8_0
/etc/logcheck/ignore.d.paranoid/mysql-server-8_0
/etc/systemd/system/multi-user.target.wants/mysql.service
/usr/bin/mysqlpump
/usr/bin/mysqld_multi
/usr/bin/mysql_migrate_keyring
/usr/bin/mysqlshow
/usr/bin/mysqloptimize
/usr/bin/mysql_ssl_rsa_setup
/usr/bin/mysqlslap
/usr/bin/mysql_config_editor
/usr/bin/mysqlreport
/usr/bin/mysqldump
/usr/bin/mysqladmin
/usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysqlimport
/usr/bin/mysqlrepair
/usr/bin/mysqld_safe
/usr/bin/mysqlanalyze
/usr/bin/mysqldumpslow
/usr/bin/mysql_upgrade
/usr/bin/mysql
/usr/bin/mysqlbinlog
/usr/bin/mysql_secure_installation
/usr/bin/mysqlcheck
/usr/sbin/mysqld
/usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/mysql.cpython-38.pyc
/usr/lib/python3/dist-packages/sos/report/plugins/mysql.py
/usr/lib/mysql
/usr/lib/mysql/plugin/mysql_no_login.so
/usr/lib/mysql/plugin/mysql_clone.so
/usr/lib/systemd/system/mysql.service
/usr/share/lintian/overrides/mysql-client-8.0
/usr/share/lintian/overrides/mysql-common
/usr/share/lintian/overrides/mysql-server-8.0
/usr/share/mysql-common
/usr/share/bash-completion/completions/mysqladmin
/usr/share/bash-completion/completions/mysql
/usr/share/vim/vim81/syntax/mysql.vim
/usr/share/man/man1/mysqlrepair.1.gz
/usr/share/man/man1/mysqladmin.1.gz
/usr/share/man/man1/mysqldumpslow.1.gz
/usr/share/man/man1/mysqloptimize.1.gz
/usr/share/man/man1/mysql.1.gz
/usr/share/man/man1/mysqlbinlog.1.gz
/usr/share/man/man1/mysqlreport.1.gz
/usr/share/man/man1/mysqldump.1.gz
/usr/share/man/man1/mysql_upgrade.1.gz
/usr/share/man/man1/mysql_tzinfo_to_sql.1.gz
/usr/share/man/man1/mysqlanalyze.1.gz
/usr/share/man/man1/mysql_config_editor.1.gz
/usr/share/man/man1/mysqlman.1.gz
/usr/share/man/man1/mysqlpump.1.gz
/usr/share/man/man1/mysqlshow.1.gz
/usr/share/man/man1/mysqld_multi.1.gz
/usr/share/man/man1/mysqld_safe.1.gz
/usr/share/man/man1/mysqlimport.1.gz
/usr/share/man/man1/mysql_ssl_rsa_setup.1.gz
/usr/share/man/man1/mysql_secure_installation.1.gz
/usr/share/man/man1/mysqlslap.1.gz
/usr/share/man/man1/mysqlcheck.1.gz
/usr/share/man/man8/mysqld.8.gz
/usr/share/mysql
/usr/share/mysql/mysqld_multi.server
/usr/share/mysql/mysql-log-rotate
/usr/share/mysql/mysql-systemd-start
/usr/share/doc/mysql-client-8.0
/usr/share/doc/mysql-common
/usr/share/doc/mysql-server-8.0
/usr/share/doc/mysql-server-8.0/mysqld.sym.gz
/usr/share/doc/mysql-client-core-8.0
/usr/share/doc/mysql-server-core-8.0
/usr/share/doc/mysql-server
/run/mysqld
/run/mysqld/mysqld.sock
/run/mysqld/mysqld.sock.lock
/run/mysqld/mysqlx.sock
/run/mysqld/mysqlx.sock.lock
/var/log/mysql
/var/cache/apt/archives/mysql-server-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/cache/apt/archives/mysql-server-core-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/cache/apt/archives/mysql-server_8.0.34-0ubuntu0.20.04.1_all.deb
/var/cache/apt/archives/mysql-client-core-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/cache/apt/archives/mysql-common_5.8+1.0.5ubuntu2_all.deb
/var/cache/apt/archives/mysql-client-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/lib/mysql-keyring
/var/lib/dpkg/info/mysql-server.list
/var/lib/dpkg/info/mysql-server-8.0.prerm
/var/lib/dpkg/info/mysql-common.preinst
/var/lib/dpkg/info/mysql-common.conffiles
/var/lib/dpkg/info/mysql-common.postinst
/var/lib/dpkg/info/mysql-common.list
/var/lib/dpkg/info/mysql-common.md5sums
/var/lib/dpkg/info/mysql-server-8.0.postrm
/var/lib/dpkg/info/mysql-common.prerm
/var/lib/dpkg/info/mysql-server-8.0.templates
/var/lib/dpkg/info/mysql-client-8.0.list
/var/lib/dpkg/info/mysql-client-core-8.0.md5sums
/var/lib/dpkg/info/mysql-server.md5sums
/var/lib/dpkg/info/mysql-server-8.0.preinst
/var/lib/dpkg/info/mysql-server-8.0.postinst
/var/lib/dpkg/info/mysql-server-8.0.conffiles
/var/lib/dpkg/info/mysql-server-8.0.md5sums
/var/lib/dpkg/info/mysql-server-8.0.list
/var/lib/dpkg/info/mysql-server-core-8.0.triggers
/var/lib/dpkg/info/mysql-server-8.0.config
/var/lib/dpkg/info/mysql-client-core-8.0.list
/var/lib/dpkg/info/mysql-server-core-8.0.md5sums
/var/lib/dpkg/info/mysql-client-8.0.md5sums
/var/lib/dpkg/info/mysql-server-core-8.0.list
/var/lib/dpkg/info/mysql-common.postrm
/var/lib/dpkg/info/mysql-server-core-8.0.shlibs
/var/lib/mysql-upgrade
/var/lib/mysql
/var/lib/mysql/mysql.ibd
/var/lib/mysql/mysql
/var/lib/mysql-files
/var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/mysql.service
/var/lib/systemd/deb-systemd-helper-enabled/mysql.service.dsh-also
/sys/fs/cgroup/pids/system.slice/mysql.service
/sys/fs/cgroup/devices/system.slice/mysql.service
/sys/fs/cgroup/memory/system.slice/mysql.service
/sys/fs/cgroup/systemd/system.slice/mysql.service
/sys/fs/cgroup/unified/system.slice/mysql.service
root@myw:~# 

卸载mysql

首先查看mysql的依赖项

dpkg --list|grep mysql
root@myw:~# dpkg --list|grep mysql
ii  mysql-client-8.0                     8.0.34-0ubuntu0.20.04.1           amd64        MySQL database client binaries
ii  mysql-client-core-8.0                8.0.34-0ubuntu0.20.04.1           amd64        MySQL database core client binaries
ii  mysql-common                         5.8+1.0.5ubuntu2                  all          MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server                         8.0.34-0ubuntu0.20.04.1           all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-8.0                     8.0.34-0ubuntu0.20.04.1           amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-8.0                8.0.34-0ubuntu0.20.04.1           amd64        MySQL database server binaries
root@myw:~# 

卸载

apt-get autoremove mysql* --purge
root@myw:~# apt-get autoremove mysql* --purge
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'mysql-source-8.0' for glob 'mysql*'
Note, selecting 'mysqltcl' for glob 'mysql*'
Note, selecting 'mysql-client-5.5' for glob 'mysql*'
Note, selecting 'mysql-client-5.6' for glob 'mysql*'
Note, selecting 'mysql-client-5.7' for glob 'mysql*'
Note, selecting 'mysql-common-5.6' for glob 'mysql*'
Note, selecting 'mysql-server-5.5' for glob 'mysql*'
Note, selecting 'mysql-server-5.6' for glob 'mysql*'
Note, selecting 'mysql-server-5.7' for glob 'mysql*'
Note, selecting 'mysql-client-8.0' for glob 'mysql*'
Note, selecting 'mysql-testsuite' for glob 'mysql*'
Note, selecting 'mysql-server' for glob 'mysql*'
Note, selecting 'mysql-router' for glob 'mysql*'
Note, selecting 'mysql-server-8.0' for glob 'mysql*'
Note, selecting 'mysql-client' for glob 'mysql*'
Note, selecting 'mysql-sandbox' for glob 'mysql*'
Note, selecting 'mysql-client-core-5.5' for glob 'mysql*'
Note, selecting 'mysql-client-core-5.6' for glob 'mysql*'
Note, selecting 'mysql-client-core-5.7' for glob 'mysql*'
Note, selecting 'mysql-client-core-8.0' for glob 'mysql*'
Note, selecting 'mysql-testsuite-5.5' for glob 'mysql*'
Note, selecting 'mysql-testsuite-5.6' for glob 'mysql*'
Note, selecting 'mysql-testsuite-5.7' for glob 'mysql*'
Note, selecting 'mysql-common' for glob 'mysql*'
Note, selecting 'mysql-testsuite-8.0' for glob 'mysql*'
Note, selecting 'mysqltuner' for glob 'mysql*'
Note, selecting 'mysql-server-core-5.5' for glob 'mysql*'
Note, selecting 'mysql-server-core-5.6' for glob 'mysql*'
Note, selecting 'mysql-server-core-5.7' for glob 'mysql*'
Note, selecting 'mysql-server-core-8.0' for glob 'mysql*'
Package 'mysql-client-5.7' is not installed, so not removed
Package 'mysql-client-core-5.7' is not installed, so not removed
Note, selecting 'mysql-common' instead of 'mysql-common-5.6'
Package 'mysql-server-5.5' is not installed, so not removed
Package 'mysql-server-5.7' is not installed, so not removed
Package 'mysql-server-core-5.7' is not installed, so not removed
Package 'mysql-client-core-5.5' is not installed, so not removed
Package 'mysql-client-core-5.6' is not installed, so not removed
Package 'mysql-client-5.5' is not installed, so not removed
Package 'mysql-client-5.6' is not installed, so not removed
Package 'mysql-server-core-5.5' is not installed, so not removed
Package 'mysql-server-core-5.6' is not installed, so not removed
Package 'mysql-server-5.6' is not installed, so not removed
Package 'mysql-testsuite-5.5' is not installed, so not removed
Package 'mysql-testsuite-5.6' is not installed, so not removed
Package 'mysql-testsuite-5.7' is not installed, so not removed
Package 'mysql-sandbox' is not installed, so not removed
Package 'mysqltcl' is not installed, so not removed
Package 'mysqltuner' is not installed, so not removed
Package 'mysql-client' is not installed, so not removed
Package 'mysql-router' is not installed, so not removed
Package 'mysql-source-8.0' is not installed, so not removed
Package 'mysql-testsuite' is not installed, so not removed
Package 'mysql-testsuite-8.0' is not installed, so not removed
The following packages will be REMOVED:
  libcgi-fast-perl* libcgi-pm-perl* libencode-locale-perl* libevent-core-2.1-7* libevent-pthreads-2.1-7* libfcgi-perl* libhtml-parser-perl* libhtml-tagset-perl* libhtml-template-perl* libhttp-date-perl* libhttp-message-perl* libio-html-perl*
  liblwp-mediatypes-perl* libmecab2* libtimedate-perl* liburi-perl* mecab-ipadic* mecab-ipadic-utf8* mecab-utils* mysql-client-8.0* mysql-client-core-8.0* mysql-common* mysql-server* mysql-server-8.0* mysql-server-core-8.0*
0 upgraded, 0 newly installed, 25 to remove and 271 not upgraded.
After this operation, 318 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 72776 files and directories currently installed.)
Removing libcgi-fast-perl (1:2.15-1) ...
Removing libhtml-template-perl (2.97-1) ...
Removing libcgi-pm-perl (4.46-1) ...
Removing libhttp-message-perl (6.22-1) ...
Removing libencode-locale-perl (1.05-1) ...
Removing mysql-server (8.0.34-0ubuntu0.20.04.1) ...
Removing mysql-server-8.0 (8.0.34-0ubuntu0.20.04.1) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Removing mysql-server-core-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Removing libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ...
Removing libevent-core-2.1-7:amd64 (2.1.11-stable-1) ...
Removing libfcgi-perl (0.79-1) ...
Removing libhtml-parser-perl (3.72-5) ...
Removing libhtml-tagset-perl (3.20-4) ...
Removing libhttp-date-perl (6.05-1) ...
Removing libio-html-perl (1.001-1) ...
Removing liblwp-mediatypes-perl (6.04-1) ...
Removing mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ...
update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
Removing mecab-ipadic (2.7.0-20070801+main-2.1) ...
Removing mecab-utils (0.996-10build1) ...
Removing libmecab2:amd64 (0.996-10build1) ...
Removing libtimedate-perl (2.3200-1) ...
Removing liburi-perl (1.76-2) ...
Removing mysql-client-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Removing mysql-client-core-8.0 (8.0.34-0ubuntu0.20.04.1) ...
Removing mysql-common (5.8+1.0.5ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
(Reading database ... 72215 files and directories currently installed.)
Purging configuration files for mysql-server-8.0 (8.0.34-0ubuntu0.20.04.1) ...
insserv: warning: script 'S03denyhosts' missing LSB tags and overrides
insserv: warning: script 'denyhosts' missing LSB tags and overrides
Purging configuration files for libmecab2:amd64 (0.996-10build1) ...
Purging configuration files for mysql-common (5.8+1.0.5ubuntu2) ...
dpkg: warning: while removing mysql-common, directory '/etc/mysql' not empty so not removed
Processing triggers for systemd (245.4-4ubuntu3.5) ...
root@myw:~# dpkg --list|grep mysql
root@myw:~# 

可以看到mysql的依赖项都卸载了,在查询有没有mysql

root@myw:~# whereis mysql
mysql: /etc/mysql
root@myw:~# 

可以看到配置文件夹还在 删除配置文件夹

root@myw:~# rm -rf /etc/mysql
root@myw:~# whereis mysql
mysql:
root@myw:~# 

再看

root@myw:~# find / -name 'mysql*'
/etc/apparmor.d/abstractions/mysql
/usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/mysql.cpython-38.pyc
/usr/lib/python3/dist-packages/sos/report/plugins/mysql.py
/usr/share/bash-completion/completions/mysqladmin
/usr/share/bash-completion/completions/mysql
/usr/share/vim/vim81/syntax/mysql.vim
/var/cache/apt/archives/mysql-server-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/cache/apt/archives/mysql-server-core-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/cache/apt/archives/mysql-server_8.0.34-0ubuntu0.20.04.1_all.deb
/var/cache/apt/archives/mysql-client-core-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/cache/apt/archives/mysql-common_5.8+1.0.5ubuntu2_all.deb
/var/cache/apt/archives/mysql-client-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/lib/mysql-keyring
/var/lib/mysql
/var/lib/mysql/mysql.ibd
/var/lib/mysql/mysql
/var/lib/mysql-files
root@myw:~# 

mysql虽然卸载了但是他的配置信息依旧是保留着的 刚刚删了/etc/mysql的配置文件夹 现在来看mysql的存储数据的地方/var/lib/mysql***
这里面的文件就是mysql原有的数据信息,一般我们都是备份后才卸载mysql的,所以这里面的文件没用了需要删掉

root@myw:~# rm -rf /var/lib/mysql
root@myw:~# rm -rf /var/lib/mysql-keyring
root@myw:~# rm -rf /var/lib/mysql-files
root@myw:~# find / -name 'mysql*'
/etc/apparmor.d/abstractions/mysql
/usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/mysql.cpython-38.pyc
/usr/lib/python3/dist-packages/sos/report/plugins/mysql.py
/usr/share/bash-completion/completions/mysqladmin
/usr/share/bash-completion/completions/mysql
/usr/share/vim/vim81/syntax/mysql.vim
/var/cache/apt/archives/mysql-server-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/cache/apt/archives/mysql-server-core-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/cache/apt/archives/mysql-server_8.0.34-0ubuntu0.20.04.1_all.deb
/var/cache/apt/archives/mysql-client-core-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
/var/cache/apt/archives/mysql-common_5.8+1.0.5ubuntu2_all.deb
/var/cache/apt/archives/mysql-client-8.0_8.0.34-0ubuntu0.20.04.1_amd64.deb
root@myw:~# 

在/var/cache/apt/archives/下关于mysql的deb文件 可以不删除 但是要改变mysql的版本 建议还是可以删除的

root@myw:~# rm -rf /var/cache/apt/archives/mysql*
root@myw:~# find / -name 'mysql*'
/etc/apparmor.d/abstractions/mysql
/usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/mysql.cpython-38.pyc
/usr/lib/python3/dist-packages/sos/report/plugins/mysql.py
/usr/share/bash-completion/completions/mysqladmin
/usr/share/bash-completion/completions/mysql
/usr/share/vim/vim81/syntax/mysql.vim
root@myw:~# 

如此在Ubuntu下面mysql算是卸载干净了。

在Ubuntu系统下安装mysql比在centos要稍显简单一点儿,其他安装方式遇到再记录

你可能感兴趣的:(开发运维工具,Ubuntu安装mysql8,Linux安装Mysql,Mysql8安装,apt安装mysql8,apt卸载mysql)