1、查看系统版本
1 root@wwqovahhked4rb48:~# uname -a 2 Linux wwqovahhked4rb48 5.4.0-70-generic #78-Ubuntu SMP Fri Mar 19 13:29:52 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux 3 root@wwqovahhked4rb48:~# uname -v 4 #78-Ubuntu SMP Fri Mar 19 13:29:52 UTC 2021 5 root@wwqovahhked4rb48:~# lsb_release -a 6 No LSB modules are available. 7 Distributor ID: Ubuntu 8 Description: Ubuntu 20.04.2 LTS 9 Release: 20.04 10 Codename: focal 11 root@wwqovahhked4rb48:~# 12 root@wwqovahhked4rb48:~# cat /etc/issue 13 Ubuntu 20.04.2 LTS \n \l 14 15 root@wwqovahhked4rb48:~# cat /proc/version 16 Linux version 5.4.0-70-generic (buildd@lcy01-amd64-004) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #78-Ubuntu SMP Fri Mar 19 13:29:52 UTC 2021 17 root@wwqovahhked4rb48:~#
2、查看系统局域网IP
1 root@wwqovahhked4rb48:~# ifconfig 2 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 3 inet 192.168.1.117 netmask 255.255.255.0 broadcast 192.168.1.255 4 inet6 fe80::f816:3eff:feb8:717d prefixlen 64 scopeid 0x20<link> 5 ether fa:16:3e:b8:71:7d txqueuelen 1000 (Ethernet) 6 RX packets 90222 bytes 180414685 (180.4 MB) 7 RX errors 0 dropped 0 overruns 0 frame 0 8 TX packets 132371 bytes 26228966 (26.2 MB) 9 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 10 11 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 12 inet 127.0.0.1 netmask 255.0.0.0 13 inet6 ::1 prefixlen 128 scopeid 0x10<host> 14 loop txqueuelen 1000 (Local Loopback) 15 RX packets 230 bytes 22849 (22.8 KB) 16 RX errors 0 dropped 0 overruns 0 frame 0 17 TX packets 230 bytes 22849 (22.8 KB) 18 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3、下载MySQL APT 安装配置包
1 root@wwqovahhked4rb48:~/app# wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb 2 --2022-10-18 14:07:06-- https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb 3 Resolving dev.mysql.com (dev.mysql.com)... 23.5.1.60, 2600:140b:2:8b6::2e31, 2600:140b:2:8ac::2e31 4 Connecting to dev.mysql.com (dev.mysql.com)|23.5.1.60|:443... connected. 5 HTTP request sent, awaiting response... 302 Moved Temporarily 6 Location: https://repo.mysql.com//mysql-apt-config_0.8.22-1_all.deb [following] 7 --2022-10-18 14:07:07-- https://repo.mysql.com//mysql-apt-config_0.8.22-1_all.deb 8 Resolving repo.mysql.com (repo.mysql.com)... 23.54.48.246 9 Connecting to repo.mysql.com (repo.mysql.com)|23.54.48.246|:443... connected. 10 HTTP request sent, awaiting response... 200 OK 11 Length: 18012 (18K) [application/x-debian-package] 12 Saving to: ‘mysql-apt-config_0.8.22-1_all.deb’ 13 14 mysql-apt-config_0.8.22-1_all.deb 100%[=======================================================================================================>] 17.59K --.-KB/s in 0.005s 15 16 2022-10-18 14:07:08 (3.41 MB/s) - ‘mysql-apt-config_0.8.22-1_all.deb’ saved [18012/18012] 17 18 root@wwqovahhked4rb48:~/app# ll 19 total 36 20 drwxr-xr-x 2 root root 4096 Oct 18 14:07 ./ 21 drwx------ 7 root root 4096 Oct 18 14:07 ../ 22 -rw-r--r-- 1 root root 612 Oct 18 07:13 index.html 23 -rw-r--r-- 1 root root 612 Oct 18 07:13 index.html.1 24 -rw-r--r-- 1 root root 18012 Jan 17 2022 mysql-apt-config_0.8.22-1_all.deb 25 root@wwqovahhked4rb48:~/app#
4、安装MySQL APT配置包
1 root@wwqovahhked4rb48:~/app# dpkg -i mysql-apt-config_0.8.22-1_all.deb 2 Selecting previously unselected package mysql-apt-config. 3 (Reading database ... 108939 files and directories currently installed.) 4 Preparing to unpack mysql-apt-config_0.8.22-1_all.deb ... 5 Unpacking mysql-apt-config (0.8.22-1) ... 6 Setting up mysql-apt-config (0.8.22-1) ... 7 Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config) 8 OK 9 root@wwqovahhked4rb48:~/app#
5、安装MySQL Server
1 root@wwqovahhked4rb48:~/app# apt-get update 2 Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease 3 Get:2 http://repo.mysql.com/apt/ubuntu focal InRelease [12.9 kB] 4 Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] 5 Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] 6 Get:5 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 Sources [963 B] 7 Get:6 http://repo.mysql.com/apt/ubuntu focal/mysql-apt-config amd64 Packages [567 B] 8 Get:7 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 Packages [8,524 B] 9 Get:8 http://repo.mysql.com/apt/ubuntu focal/mysql-tools amd64 Packages [6,126 B] 10 Get:9 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB] 11 Fetched 365 kB in 2s (161 kB/s) 12 Reading package lists... Done 13 root@wwqovahhked4rb48:~/app# apt-get install mysql-server 14 Reading package lists... Done 15 Building dependency tree 16 Reading state information... Done 17 The following additional packages will be installed: 18 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server 19 mysql-community-server-core 20 The following NEW packages will be installed: 21 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server 22 mysql-community-server-core mysql-server 23 0 upgraded, 12 newly installed, 0 to remove and 81 not upgraded. 24 Need to get 42.9 MB of archives. 25 After this operation, 358 MB of additional disk space will be used. 26 Do you want to continue? [Y/n] Y 27 Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 libmecab2 amd64 0.996-10build1 [233 kB] 28 Get:2 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-common amd64 8.0.31-1ubuntu20.04 [72.3 kB] 29 Get:3 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-client-plugins amd64 8.0.31-1ubuntu20.04 [1,274 kB] 30 Get:4 http://archive.ubuntu.com/ubuntu focal/main amd64 mecab-utils amd64 0.996-10build1 [4,912 B] 31 Get:5 http://archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic all 2.7.0-20070801+main-2.1 [6,714 kB] 32 Get:6 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-client-core amd64 8.0.31-1ubuntu20.04 [1,907 kB] 33 Get:7 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-client amd64 8.0.31-1ubuntu20.04 [3,489 kB] 34 Get:8 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-client amd64 8.0.31-1ubuntu20.04 [68.3 kB] 35 Get:9 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-server-core amd64 8.0.31-1ubuntu20.04 [28.9 MB] 36 Get:10 http://archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic-utf8 all 2.7.0-20070801+main-2.1 [4,380 B] 37 Get:11 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-server amd64 8.0.31-1ubuntu20.04 [79.4 kB] 38 Get:12 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-server amd64 8.0.31-1ubuntu20.04 [68.3 kB] 39 Fetched 42.9 MB in 10s (4,203 kB/s) 40 Preconfiguring packages ... 41 Selecting previously unselected package mysql-common. 42 (Reading database ... 108944 files and directories currently installed.) 43 Preparing to unpack .../00-mysql-common_8.0.31-1ubuntu20.04_amd64.deb ... 44 Unpacking mysql-common (8.0.31-1ubuntu20.04) ... 45 Selecting previously unselected package mysql-community-client-plugins. 46 Preparing to unpack .../01-mysql-community-client-plugins_8.0.31-1ubuntu20.04_amd64.deb ... 47 Unpacking mysql-community-client-plugins (8.0.31-1ubuntu20.04) ... 48 Selecting previously unselected package mysql-community-client-core. 49 Preparing to unpack .../02-mysql-community-client-core_8.0.31-1ubuntu20.04_amd64.deb ... 50 Unpacking mysql-community-client-core (8.0.31-1ubuntu20.04) ... 51 Selecting previously unselected package mysql-community-client. 52 Preparing to unpack .../03-mysql-community-client_8.0.31-1ubuntu20.04_amd64.deb ... 53 Unpacking mysql-community-client (8.0.31-1ubuntu20.04) ... 54 Selecting previously unselected package mysql-client. 55 Preparing to unpack .../04-mysql-client_8.0.31-1ubuntu20.04_amd64.deb ... 56 Unpacking mysql-client (8.0.31-1ubuntu20.04) ... 57 Selecting previously unselected package libmecab2:amd64. 58 Preparing to unpack .../05-libmecab2_0.996-10build1_amd64.deb ... 59 Unpacking libmecab2:amd64 (0.996-10build1) ... 60 Selecting previously unselected package mysql-community-server-core. 61 Preparing to unpack .../06-mysql-community-server-core_8.0.31-1ubuntu20.04_amd64.deb ... 62 Unpacking mysql-community-server-core (8.0.31-1ubuntu20.04) ... 63 Selecting previously unselected package mysql-community-server. 64 Preparing to unpack .../07-mysql-community-server_8.0.31-1ubuntu20.04_amd64.deb ... 65 Unpacking mysql-community-server (8.0.31-1ubuntu20.04) ... 66 Selecting previously unselected package mecab-utils. 67 Preparing to unpack .../08-mecab-utils_0.996-10build1_amd64.deb ... 68 Unpacking mecab-utils (0.996-10build1) ... 69 Selecting previously unselected package mecab-ipadic. 70 Preparing to unpack .../09-mecab-ipadic_2.7.0-20070801+main-2.1_all.deb ... 71 Unpacking mecab-ipadic (2.7.0-20070801+main-2.1) ... 72 Selecting previously unselected package mecab-ipadic-utf8. 73 Preparing to unpack .../10-mecab-ipadic-utf8_2.7.0-20070801+main-2.1_all.deb ... 74 Unpacking mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... 75 Selecting previously unselected package mysql-server. 76 Preparing to unpack .../11-mysql-server_8.0.31-1ubuntu20.04_amd64.deb ... 77 Unpacking mysql-server (8.0.31-1ubuntu20.04) ... 78 Setting up libmecab2:amd64 (0.996-10build1) ... 79 Setting up mysql-common (8.0.31-1ubuntu20.04) ... 80 update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode 81 Setting up mysql-community-server-core (8.0.31-1ubuntu20.04) ... 82 Setting up mecab-utils (0.996-10build1) ... 83 Setting up mysql-community-client-plugins (8.0.31-1ubuntu20.04) ... 84 Setting up mecab-ipadic (2.7.0-20070801+main-2.1) ... 85 Compiling IPA dictionary for Mecab. This takes long time... 86 reading /usr/share/mecab/dic/ipadic/unk.def ... 40 87 emitting double-array: 100% |###########################################| 88 /usr/share/mecab/dic/ipadic/model.def is not found. skipped. 89 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 90 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 91 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 92 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 93 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 94 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 95 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 96 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 97 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 98 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 99 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 100 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 101 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 102 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 103 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 104 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 105 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 106 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 107 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 108 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 109 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 110 reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 111 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 112 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 113 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 114 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 115 emitting double-array: 100% |###########################################| 116 reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 117 emitting matrix : 100% |###########################################| 118 119 done! 120 update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode 121 Setting up mysql-community-client-core (8.0.31-1ubuntu20.04) ... 122 Setting up mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... 123 Compiling IPA dictionary for Mecab. This takes long time... 124 reading /usr/share/mecab/dic/ipadic/unk.def ... 40 125 emitting double-array: 100% |###########################################| 126 /usr/share/mecab/dic/ipadic/model.def is not found. skipped. 127 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 128 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 129 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 130 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 131 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 132 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 133 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 134 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 135 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 136 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 137 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 138 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 139 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 140 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 141 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 142 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 143 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 144 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 145 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 146 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 147 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 148 reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 149 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 150 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 151 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 152 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 153 emitting double-array: 100% |###########################################| 154 reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 155 emitting matrix : 100% |###########################################| 156 157 done! 158 update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode 159 Setting up mysql-community-client (8.0.31-1ubuntu20.04) ... 160 Setting up mysql-client (8.0.31-1ubuntu20.04) ... 161 Setting up mysql-community-server (8.0.31-1ubuntu20.04) ... 162 update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode 163 Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service. 164 Setting up mysql-server (8.0.31-1ubuntu20.04) ... 165 Processing triggers for man-db (2.9.1-1) ... 166 Processing triggers for libc-bin (2.31-0ubuntu9.7) ... 167 root@wwqovahhked4rb48:~/app#
6、查看Mysql是否启动成功
1 root@wwqovahhked4rb48:~/app# ps -ef | grep mysql 2 mysql 168681 1 1 14:16 ? 00:00:01 /usr/sbin/mysqld 3 root 170828 152216 0 14:19 pts/0 00:00:00 grep --color=auto mysql 4 root@wwqovahhked4rb48:~/app# netstat -anp | grep mysql 5 tcp6 0 0 :::33060 :::* LISTEN 168681/mysqld 6 tcp6 0 0 :::3306 :::* LISTEN 168681/mysqld 7 unix 2 [ ACC ] STREAM LISTENING 1013810 168681/mysqld /var/run/mysqld/mysqlx.sock 8 unix 2 [ ACC ] STREAM LISTENING 1013813 168681/mysqld /var/run/mysqld/mysqld.sock 9 unix 2 [ ] DGRAM 1013679 168681/mysqld 10 root@wwqovahhked4rb48:~/app# 11 root@wwqovahhked4rb48:~/app# service mysql status 12 ● mysql.service - MySQL Community Server 13 Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) 14 Active: active (running) since Tue 2022-10-18 14:16:42 UTC; 4min 8s ago 15 Docs: man:mysqld(8) 16 http://dev.mysql.com/doc/refman/en/using-systemd.html 17 Main PID: 168681 (mysqld) 18 Status: "Server is operational" 19 Tasks: 38 (limit: 4618) 20 Memory: 360.4M 21 CGroup: /system.slice/mysql.service 22 └─168681 /usr/sbin/mysqld 23 24 Oct 18 14:16:41 wwqovahhked4rb48 systemd[1]: Starting MySQL Community Server... 25 Oct 18 14:16:42 wwqovahhked4rb48 systemd[1]: Started MySQL Community Server. 26 root@wwqovahhked4rb48:~/app#
7、配置外网访问
1 root@wwqovahhked4rb48:~/app# mysql -uroot -p 2 Enter password: 3 Welcome to the MySQL monitor. Commands end with ; or \g. 4 Your MySQL connection id is 8 5 Server version: 8.0.31 MySQL Community Server - GPL 6 7 Copyright (c) 2000, 2022, Oracle and/or its affiliates. 8 9 Oracle is a registered trademark of Oracle Corporation and/or its 10 affiliates. Other names may be trademarks of their respective 11 owners. 12 13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 14 15 mysql> use mysql; 16 Reading table information for completion of table and column names 17 You can turn off this feature to get a quicker startup with -A 18 19 Database changed 20 mysql> select user,host from user; 21 +------------------+-----------+ 22 | user | host | 23 +------------------+-----------+ 24 | mysql.infoschema | localhost | 25 | mysql.session | localhost | 26 | mysql.sys | localhost | 27 | root | localhost | 28 +------------------+-----------+ 29 4 rows in set (0.00 sec) 30 31 mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'Mysql@1234'; 32 Query OK, 0 rows affected (0.02 sec) 33 34 mysql> grant all privileges on *.* to 'root'@'%'; 35 Query OK, 0 rows affected (0.01 sec) 36 37 mysql> alter user 'root'@'%' identified with mysql_native_password by 'Mysql@1234'; 38 Query OK, 0 rows affected (0.00 sec) 39 40 mysql> flush privileges; 41 Query OK, 0 rows affected (0.01 sec) 42 43 mysql> select user,host from user; 44 +------------------+-----------+ 45 | user | host | 46 +------------------+-----------+ 47 | root | % | 48 | mysql.infoschema | localhost | 49 | mysql.session | localhost | 50 | mysql.sys | localhost | 51 | root | localhost | 52 +------------------+-----------+ 53 5 rows in set (0.00 sec) 54 55 mysql>
8、Mysql相关知识点收集
标签:ubuntu20.04,...,天翼云,Mysql8,ipadic,mecab,dic,usr,mysql From: https://www.cnblogs.com/leorain/p/16804523.html数据库目录:/var/lib/mysql/。
配置文件:/usr/share/mysql-8.0(命令及配置文件),/etc/mysql(如my.cnf)。
相关命令:/usr/bin(mysqladmin、mysqldump等命令)和/usr/sbin。
启动脚本:/etc/init.d/mysql(启动脚本文件mysql的目录)。
# 查看服务状态
service mysql status# 停止服务
service mysql stop# 启动服务
service mysql start# 重启服务
service mysql restart
删除mysql
apt purge mysql-*
rm -rf /etc/mysql/ /var/lib/mysql
apt autoremove
apt autoclean