Ubuntu 20.04源安装MySQL5.7.42步骤说明
mes@mes:~$
mes@mes:~$
mes@mes:~$ sudo -i
[sudo] mes 的密码:
root@mes:~# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.60.120.66 netmask 255.255.255.0 broadcast 10.60.120.255
inet6 fe80::fc30:251a:cab1:87 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:23:1a:f5 txqueuelen 1000 (以太网)
RX packets 230244 bytes 418655894 (418.6 MB)
RX errors 0 dropped 186 overruns 0 frame 0
TX packets 133233 bytes 12548135 (12.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 432 bytes 40173 (40.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 432 bytes 40173 (40.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@mes:~# dpkg --list|grep mysql
ii libmysqlclient21:amd64 8.0.32-0ubuntu0.20.04.2 amd64 MySQL database client library
ii mysql-common 5.8+1.0.5ubuntu2 all MySQL database common files, e.g. /etc/mysql/my.cnf
root@mes:~#
root@mes:~#
root@mes:~# apt-get remove mysql-common
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
下列软件包是自动安装的并且现在不需要了:
acl apg colord-data gnome-control-center-faces gnome-online-accounts hplip-data libcolord-gtk1 libcolorhug2 libgsound0 libgssdp-1.2-0 libgupnp-1.2-0 libgupnp-av-1.0-2
libgupnp-dlna-2.0-3 libieee1284-3 libimagequant0 librygel-core-2.6-2 librygel-db-2.6-2 librygel-renderer-2.6-2 librygel-server-2.6-2 libsane-common libsnmp-base libwebpmux3
mobile-broadband-provider-info network-manager-gnome printer-driver-postscript-hp python3-macaroonbakery python3-olefile python3-pil python3-protobuf python3-pymacaroons
python3-renderpm python3-reportlab python3-reportlab-accel python3-rfc3339 python3-tz rygel
使用'apt autoremove'来卸载它(它们)。
下列软件包将被【卸载】:
colord gnome-control-center hplip libhpmud0 libmysqlclient21 libsane libsane-hpaio libsnmp35 mysql-common printer-driver-hpcups sane-utils simple-scan ubuntu-desktop
ubuntu-desktop-minimal
升级了 0 个软件包,新安装了 0 个软件包,要卸载 14 个软件包,有 284 个软件包未被升级。
解压缩后将会空出 37.8 MB 的空间。
您希望继续执行吗? [Y/n] y
(正在读取数据库 ... 系统当前共安装有 188481 个文件和目录。)
正在卸载 ubuntu-desktop (1.450.2) ...
正在卸载 ubuntu-desktop-minimal (1.450.2) ...
正在卸载 gnome-control-center (1:3.36.5-0ubuntu4) ...
正在卸载 colord (1.4.4-2) ...
正在卸载 hplip (3.20.3+dfsg0-2) ...
正在卸载 libsane-hpaio:amd64 (3.20.3+dfsg0-2) ...
正在卸载 printer-driver-hpcups (3.20.3+dfsg0-2) ...
正在卸载 libhpmud0:amd64 (3.20.3+dfsg0-2) ...
正在卸载 sane-utils (1.0.29-0ubuntu5.2) ...
正在卸载 simple-scan (3.36.3-0ubuntu0.20.04.0) ...
正在卸载 libsane:amd64 (1.0.29-0ubuntu5.2) ...
正在卸载 libsnmp35:amd64 (5.8+dfsg-2ubuntu2.6) ...
正在卸载 libmysqlclient21:amd64 (8.0.32-0ubuntu0.20.04.2) ...
正在卸载 mysql-common (5.8+1.0.5ubuntu2) ...
正在处理用于 mime-support (3.64ubuntu1) 的触发器 ...
正在处理用于 hicolor-icon-theme (0.17-2) 的触发器 ...
正在处理用于 cups (2.3.1-9ubuntu1.2) 的触发器 ...
Updating PPD files for cups-filters ...
Updating PPD files for foomatic-db-compressed-ppds ...
Updating PPD files for openprinting-ppds ...
Updating PPD files for brlaser ...
Updating PPD files for c2esp ...
Updating PPD files for foo2zjs-common ...
Updating PPD files for m2300w ...
Updating PPD files for postscript-hp ...
Updating PPD files for ptouch ...
Updating PPD files for pxljr ...
Updating PPD files for sag-gdi ...
Updating PPD files for splix ...
正在处理用于 gnome-menus (3.36.0-1ubuntu1) 的触发器 ...
正在处理用于 libglib2.0-0:amd64 (2.64.6-1~ubuntu20.04.4) 的触发器 ...
正在处理用于 libc-bin (2.31-0ubuntu9.9) 的触发器 ...
正在处理用于 man-db (2.9.1-1) 的触发器 ...
正在处理用于 dbus (1.12.16-2ubuntu2.3) 的触发器 ...
正在处理用于 udev (245.4-4ubuntu3.23) 的触发器 ...
正在处理用于 desktop-file-utils (0.24-1ubuntu3) 的触发器 ...
root@mes:~# dpkg --list|grep mysql
rc mysql-common 5.8+1.0.5ubuntu2 all MySQL database common files, e.g. /etc/mysql/my.cnf
root@mes:~#
root@mes:~# apt-get autoremove --purge mysql-server-8.0
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
软件包 mysql-server-8.0 未安装,所以不会被卸载
下列软件包将被【卸载】:
acl* apg* colord-data* gnome-control-center-faces* gnome-online-accounts* hplip-data* libcolord-gtk1* libcolorhug2* libgsound0* libgssdp-1.2-0* libgupnp-1.2-0*
libgupnp-av-1.0-2* libgupnp-dlna-2.0-3* libieee1284-3* libimagequant0* librygel-core-2.6-2* librygel-db-2.6-2* librygel-renderer-2.6-2* librygel-server-2.6-2* libsane-common*
libsnmp-base* libwebpmux3* mobile-broadband-provider-info* network-manager-gnome* printer-driver-postscript-hp* python3-macaroonbakery* python3-olefile* python3-pil*
python3-protobuf* python3-pymacaroons* python3-renderpm* python3-reportlab* python3-reportlab-accel* python3-rfc3339* python3-tz* rygel*
升级了 0 个软件包,新安装了 0 个软件包,要卸载 36 个软件包,有 277 个软件包未被升级。
解压缩后将会空出 34.0 MB 的空间。
您希望继续执行吗? [Y/n] y
(正在读取数据库 ... 系统当前共安装有 187379 个文件和目录。)
正在卸载 acl (2.2.53-6) ...
正在卸载 apg (2.2.3.dfsg.1-5) ...
正在卸载 colord-data (1.4.4-2) ...
正在卸载 gnome-control-center-faces (1:3.36.5-0ubuntu4) ...
正在卸载 gnome-online-accounts (3.36.1-0ubuntu1) ...
正在卸载 hplip-data (3.20.3+dfsg0-2) ...
dpkg: 警告: 卸载 hplip-data 时,目录 /usr/share/hplip/ui5 非空,因而不会删除该目录
dpkg: 警告: 卸载 hplip-data 时,目录 /usr/share/hplip/scan 非空,因而不会删除该目录
dpkg: 警告: 卸载 hplip-data 时,目录 /usr/share/hplip/prnt 非空,因而不会删除该目录
dpkg: 警告: 卸载 hplip-data 时,目录 /usr/share/hplip/pcard 非空,因而不会删除该目录
dpkg: 警告: 卸载 hplip-data 时,目录 /usr/share/hplip/installer 非空,因而不会删除该目录
dpkg: 警告: 卸载 hplip-data 时,目录 /usr/share/hplip/fax 非空,因而不会删除该目录
dpkg: 警告: 卸载 hplip-data 时,目录 /usr/share/hplip/copier 非空,因而不会删除该目录
dpkg: 警告: 卸载 hplip-data 时,目录 /usr/share/hplip/base/pexpect 非空,因而不会删除该目录
正在卸载 libcolord-gtk1:amd64 (0.2.0-0ubuntu1) ...
正在卸载 libcolorhug2:amd64 (1.4.4-2) ...
正在卸载 libgsound0:amd64 (1.0.2-4) ...
正在卸载 rygel (0.38.3-1ubuntu1) ...
正在卸载 librygel-db-2.6-2:amd64 (0.38.3-1ubuntu1) ...
正在卸载 librygel-server-2.6-2:amd64 (0.38.3-1ubuntu1) ...
正在卸载 librygel-renderer-2.6-2:amd64 (0.38.3-1ubuntu1) ...
正在卸载 libgupnp-av-1.0-2 (0.12.11-2) ...
正在卸载 libgupnp-dlna-2.0-3 (0.10.5-4) ...
正在卸载 libieee1284-3:amd64 (0.2.11-13build1) ...
正在卸载 python3-reportlab (3.5.34-1ubuntu1) ...
正在卸载 python3-pil:amd64 (7.0.0-4ubuntu0.7) ...
正在卸载 libimagequant0:amd64 (2.12.2-1.1) ...
正在卸载 libsane-common (1.0.29-0ubuntu5.2) ...
正在卸载 libsnmp-base (5.8+dfsg-2ubuntu2.6) ...
正在卸载 libwebpmux3:amd64 (0.6.1-2ubuntu0.20.04.1) ...
正在卸载 mobile-broadband-provider-info (20190618-3) ...
正在卸载 network-manager-gnome (1.8.24-1ubuntu3) ...
正在卸载 printer-driver-postscript-hp (3.20.3+dfsg0-2) ...
正在卸载 python3-macaroonbakery (1.3.1-1) ...
正在卸载 python3-olefile (0.46-2) ...
正在卸载 python3-protobuf (3.6.1.3-2ubuntu5.2) ...
正在卸载 python3-pymacaroons (0.13.0-3) ...
正在卸载 python3-renderpm:amd64 (3.5.34-1ubuntu1) ...
正在卸载 python3-reportlab-accel:amd64 (3.5.34-1ubuntu1) ...
正在卸载 python3-rfc3339 (1.1-2) ...
正在卸载 python3-tz (2019.3-1ubuntu0.20.04.0) ...
正在卸载 librygel-core-2.6-2:amd64 (0.38.3-1ubuntu1) ...
正在卸载 libgupnp-1.2-0:amd64 (1.2.4-0ubuntu1) ...
正在卸载 libgssdp-1.2-0:amd64 (1.2.3-0ubuntu0.20.04.1) ...
正在处理用于 mime-support (3.64ubuntu1) 的触发器 ...
正在处理用于 hicolor-icon-theme (0.17-2) 的触发器 ...
正在处理用于 cups (2.3.1-9ubuntu1.2) 的触发器 ...
正在处理用于 gnome-menus (3.36.0-1ubuntu1) 的触发器 ...
正在处理用于 libglib2.0-0:amd64 (2.64.6-1~ubuntu20.04.4) 的触发器 ...
正在处理用于 libc-bin (2.31-0ubuntu9.9) 的触发器 ...
正在处理用于 man-db (2.9.1-1) 的触发器 ...
正在处理用于 desktop-file-utils (0.24-1ubuntu3) 的触发器 ...
(正在读取数据库 ... 系统当前共安装有 185538 个文件和目录。)
正在清除 network-manager-gnome (1.8.24-1ubuntu3) 的配置文件 ...
正在清除 libsnmp-base (5.8+dfsg-2ubuntu2.6) 的配置文件 ...
正在清除 apg (2.2.3.dfsg.1-5) 的配置文件 ...
正在清除 rygel (0.38.3-1ubuntu1) 的配置文件 ...
正在清除 acl (2.2.53-6) 的配置文件 ...
正在清除 libsane-common (1.0.29-0ubuntu5.2) 的配置文件 ...
Removing directory /etc/sane.d/ ...
root@mes:~#
root@mes:~# dpkg --list|grep mysql
rc mysql-common 5.8+1.0.5ubuntu2 all MySQL database common files, e.g. /etc/mysql/my.cnf
root@mes:~#
root@mes:~# dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P
(正在读取数据库 ... 系统当前共安装有 185454 个文件和目录。)
正在清除 colord (1.4.4-2) 的配置文件 ...
正在清除 hplip (3.20.3+dfsg0-2) 的配置文件 ...
正在清除 libsane-hpaio:amd64 (3.20.3+dfsg0-2) 的配置文件 ...
正在清除 mysql-common (5.8+1.0.5ubuntu2) 的配置文件 ...
正在清除 sane-utils (1.0.29-0ubuntu5.2) 的配置文件 ...
正在处理用于 dbus (1.12.16-2ubuntu2.3) 的触发器 ...
正在处理用于 systemd (245.4-4ubuntu3.20) 的触发器 ...
root@mes:~#
root@mes:~# dpkg --list|grep mysql
root@mes:~#
root@mes:~# apt-get autoremove --purge mysql-apt-config
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
E: 无法定位软件包 mysql-apt-config
root@mes:~#
root@mes:~# rm -rf /etc/mysql /var/lib/mysql
root@mes:~#
root@mes:~#
root@mes:~# apt-get update
命中:1 http://security.ubuntu.com/ubuntu focal-security InRelease
命中:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease
命中:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease
命中:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease
正在读取软件包列表... 完成
root@mes:~#
root@mes:~#
root@mes:~# apt-cache policy mysql-server
mysql-server:
已安装:(无)
候选: 8.0.36-0ubuntu0.20.04.1
版本列表:
8.0.36-0ubuntu0.20.04.1 500
500 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
500 http://cn.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://cn.archive.ubuntu.com/ubuntu focal/main amd64 Packages
500 http://cn.archive.ubuntu.com/ubuntu focal/main i386 Packages
root@mes:~#
root@mes:~#
root@mes:~#
root@mes:~# cp /etc/apt/sources.list /etc/apt/sources.list.back
root@mes:~#
root@mes:~#
root@mes:~# vim /etc/apt/sources.list
root@mes:~#
root@mes:~#
root@mes:~# apt-get update
root@mes:~#
root@mes:~#
root@mes:~# apt-cache policy mysql-server
mysql-server:
已安装:(无)
候选: 5.7.42-0ubuntu0.18.04.1
版本列表:
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
root@mes:~#
root@mes:~#
root@mes:~#
root@mes:~# apt-get -y install mysql-server-5.7
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会同时安装下列软件:
libaio1 libcgi-pm-perl libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-core-5.7
建议安装:
libipc-sharedcache-perl mailx tinyca
推荐安装:
libcgi-fast-perl
下列【新】软件包将被安装:
libaio1 libcgi-pm-perl libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
升级了 0 个软件包,新安装了 9 个软件包,要卸载 0 个软件包,有 33 个软件包未被升级。
需要下载 19.7 MB 的归档。
解压缩后会消耗 156 MB 的额外空间。
获取:1 http://mirrors.aliyun.com/ubuntu bionic/main amd64 mysql-common all 5.8+1.0.4 [7,308 B]
获取:2 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 libaio1 amd64 0.3.110-5ubuntu0.1 [6,476 B]
获取:3 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 mysql-client-core-5.7 amd64 5.7.42-0ubuntu0.18.04.1 [6,752 kB]
获取:4 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 mysql-client-5.7 amd64 5.7.42-0ubuntu0.18.04.1 [2,028 kB]
获取:5 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 mysql-server-core-5.7 amd64 5.7.42-0ubuntu0.18.04.1 [7,542 kB]
获取:6 http://mirrors.aliyun.com/ubuntu bionic/main amd64 libevent-core-2.1-6 amd64 2.1.8-stable-4build1 [85.9 kB]
获取:7 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 mysql-server-5.7 amd64 5.7.42-0ubuntu0.18.04.1 [3,011 kB]
获取:8 http://mirrors.aliyun.com/ubuntu bionic/main amd64 libcgi-pm-perl all 4.38-1 [185 kB]
获取:9 http://mirrors.aliyun.com/ubuntu bionic/main amd64 libhtml-template-perl all 2.97-1 [59.0 kB]
已下载 19.7 MB,耗时 5秒 (3,735 kB/s)
正在预设定软件包 ...
正在选中未选择的软件包 mysql-common。
(正在读取数据库 ... 系统当前共安装有 185537 个文件和目录。)
准备解压 .../0-mysql-common_5.8+1.0.4_all.deb ...
正在解压 mysql-common (5.8+1.0.4) ...
正在选中未选择的软件包 libaio1:amd64。
准备解压 .../1-libaio1_0.3.110-5ubuntu0.1_amd64.deb ...
正在解压 libaio1:amd64 (0.3.110-5ubuntu0.1) ...
正在选中未选择的软件包 mysql-client-core-5.7。
准备解压 .../2-mysql-client-core-5.7_5.7.42-0ubuntu0.18.04.1_amd64.deb ...
正在解压 mysql-client-core-5.7 (5.7.42-0ubuntu0.18.04.1) ...
正在选中未选择的软件包 mysql-client-5.7。
准备解压 .../3-mysql-client-5.7_5.7.42-0ubuntu0.18.04.1_amd64.deb ...
正在解压 mysql-client-5.7 (5.7.42-0ubuntu0.18.04.1) ...
正在选中未选择的软件包 mysql-server-core-5.7。
准备解压 .../4-mysql-server-core-5.7_5.7.42-0ubuntu0.18.04.1_amd64.deb ...
正在解压 mysql-server-core-5.7 (5.7.42-0ubuntu0.18.04.1) ...
正在选中未选择的软件包 libevent-core-2.1-6:amd64。
准备解压 .../5-libevent-core-2.1-6_2.1.8-stable-4build1_amd64.deb ...
正在解压 libevent-core-2.1-6:amd64 (2.1.8-stable-4build1) ...
正在设置 mysql-common (5.8+1.0.4) ...
update-alternatives: 使用 /etc/mysql/my.cnf.fallback 来在自动模式中提供 /etc/mysql/my.cnf (my.cnf)
正在选中未选择的软件包 mysql-server-5.7。
(正在读取数据库 ... 系统当前共安装有 185705 个文件和目录。)
准备解压 .../mysql-server-5.7_5.7.42-0ubuntu0.18.04.1_amd64.deb ...
正在解压 mysql-server-5.7 (5.7.42-0ubuntu0.18.04.1) ...
正在选中未选择的软件包 libcgi-pm-perl。
准备解压 .../libcgi-pm-perl_4.38-1_all.deb ...
正在解压 libcgi-pm-perl (4.38-1) ...
正在选中未选择的软件包 libhtml-template-perl。
准备解压 .../libhtml-template-perl_2.97-1_all.deb ...
正在解压 libhtml-template-perl (2.97-1) ...
正在设置 libcgi-pm-perl (4.38-1) ...
正在设置 libhtml-template-perl (2.97-1) ...
正在设置 libevent-core-2.1-6:amd64 (2.1.8-stable-4build1) ...
正在设置 libaio1:amd64 (0.3.110-5ubuntu0.1) ...
正在设置 mysql-server-core-5.7 (5.7.42-0ubuntu0.18.04.1) ...
正在设置 mysql-client-core-5.7 (5.7.42-0ubuntu0.18.04.1) ...
正在设置 mysql-client-5.7 (5.7.42-0ubuntu0.18.04.1) ...
正在设置 mysql-server-5.7 (5.7.42-00.18.04.1) ...
update-alternatives: 使用 /etc/mysql/mysql.cnf 来在自动模式中提供 /etc/mysql/my.cnf (my.cnf)
Renaming removed key_buffer and myisam-recover options (if present)
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
正在处理用于 man-db (2.9.1-1) 的触发器 ...
正在处理用于 libc-bin (2.31-0ubuntu9.14) 的触发器 ...
正在处理用于 systemd (245.4-4ubuntu3.23) 的触发器 ...
root@mes:~#
root@mes:~# dpkg -l | grep mysql
ii mysql-client-5.7 5.7.42-0ubuntu0.18.04.1 amd64 MySQL database client binaries
ii mysql-client-core-5.7 5.7.42-0ubuntu0.18.04.1 amd64 MySQL database core client binaries
ii mysql-common 5.8+1.0.4 all MySQL database common files, e.g. /etc/mysql/my.cnf
ii mysql-server-5.7 5.7.42-0ubuntu0.18.04.1 amd64 MySQL database server binaries and system database setup
ii mysql-server-core-5.7 5.7.42-0ubuntu0.18.04.1 amd64 MySQL database server binaries
root@mes:~#
root@mes:~# systemctl enable mysql
Synchronizing state of mysql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mysql
root@mes:~#
root@mes:~# mysql -V
mysql Ver 14.14 Distrib 5.7.42, for Linux (x86_64) using EditLine wrapper
root@mes:~#
root@mes:~# systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2024-04-03 11:31:49 CST; 46s ago
Main PID: 12200 (mysqld)
Tasks: 27 (limit: 19090)
Memory: 172.7M
CGroup: /system.slice/mysql.service
└─12200 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
4月 03 11:31:49 mes systemd[1]: Starting MySQL Community Server...
4月 03 11:31:49 mes systemd[1]: Started MySQL Community Server.
root@mes:~#
root@mes:~# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.42-0ubuntu0.18.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>
mysql>
mysql> select user,plugin, authentication_string,Host from mysql.user;
+------------------+-----------------------+-------------------------------------------+-----------+
| user | plugin | authentication_string | Host |
+------------------+-----------------------+-------------------------------------------+-----------+
| root | auth_socket | | localhost |
| mysql.session | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| debian-sys-maint | mysql_native_password | *D0474CC1F19159C4B6BD85CBBA5E35C8B57CCA26 | localhost |
+------------------+-----------------------+-------------------------------------------+-----------+
4 rows in set (0.00 sec)
mysql>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'nn@aa202404';
Query OK, 0 rows affected (0.00 sec)
mysql> update mysql.user set Host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE USER 'nn'@'%' IDENTIFIED BY 'aa@nn202404';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'nn'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,plugin, authentication_string,Host from mysql.user;
+------------------+-----------------------+-------------------------------------------+-----------+
| user | plugin | authentication_string | Host |
+------------------+-----------------------+-------------------------------------------+-----------+
| root | mysql_native_password | *03D7C36551189D49D5FE011327B04BDA42F69F5D | % |
| mysql.session | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| debian-sys-maint | mysql_native_password | *D0474CC1F19159C4B6BD85CBBA5E35C8B57CCA26 | localhost |
| hainai | mysql_native_password | *DE8ABAFF1A661BE3C5890C94755CF0B40A3C14F4 | % |
+------------------+-----------------------+-------------------------------------------+-----------+
5 rows in set (0.00 sec)
mysql>
root@mes:~# cd /etc/mysql
root@mes:/etc/mysql#
root@mes:/etc/mysql# ls
conf.d debian.cnf debian-start my.cnf my.cnf.fallback mysql.cnf mysql.conf.d
root@mes:/etc/mysql#
root@mes:/etc/mysql# cat my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# 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
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
root@mes:/etc/mysql#
root@mes:/etc/mysql# cd mysql.conf.d/
root@mes:/etc/mysql/mysql.conf.d#
root@mes:/etc/mysql/mysql.conf.d# ls
mysqld.cnf mysqld_safe_syslog.cnf
root@mes:/etc/mysql/mysql.conf.d#
root@mes:/etc/mysql/mysql.conf.d# cat mysqld.cnf
##########################################################################################################################################
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# 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
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# 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
#
# * Fine Tuning
#
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
#max_connections = 100
#table_open_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.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
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
##########################################################################################################################################
root@mes:/etc/mysql/mysql.conf.d# vim mysqld.cnf
root@mes:/etc/mysql/mysql.conf.d#
root@mes:/etc/mysql/mysql.conf.d# cd /home
root@mes:/home# mkdir mysql
root@mes:/home# cd mysql
root@mes:/home/mysql# mkdir data
root@mes:/home/mysql# cd data
root@mes:/home/mysql/data# systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2024-04-03 11:36:24 CST; 5min ago
Process: 16680 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Process: 16689 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
Main PID: 16691 (mysqld)
Tasks: 28 (limit: 19090)
Memory: 172.7M
CGroup: /system.slice/mysql.service
└─16691 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
4月 03 11:36:24 mes systemd[1]: Starting MySQL Community Server...
4月 03 11:36:24 mes systemd[1]: Started MySQL Community Server.
root@mes:/home/mysql/data#
root@mes:/home/mysql/data# systemctl stop mysql
root@mes:/home/mysql/data#
root@mes:/home/mysql/data# cp -a /var/lib/mysql/* /home/mysql/data
root@mes:/home/mysql/data#
root@mes:/home/mysql/data#
root@mes:/home/mysql/data# vim /etc/mysql/mysql.conf.d/mysqld.cnf
root@mes:/home/mysql/data#
root@mes:/home/mysql/data# systemctl start mysql
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
root@mes:/home/mysql/data#
root@mes:/home/mysql/data# chown -R 777 /home/mysql
root@mes:/home/mysql/data# chown -R mysql:mysql /home/mysql
root@mes:/home/mysql/data#
root@mes:/home/mysql/data# vim /etc/apparmor.d/usr.sbin.mysqld
root@mes:/home/mysql/data#
root@mes:/home/mysql/data# systemctl restart apparmor
root@mes:/home/mysql/data#
root@mes:/home/mysql/data# systemctl restart mysql
root@mes:/home/mysql/data#
root@mes:/home/mysql/data#
root@mes:/home/mysql/data# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.42-0ubuntu0.18.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> show variables like '%datadir%';
+---------------+-------------------+
| Variable_name | Value |
+---------------+-------------------+
| datadir | /home/mysql/data/ |
+---------------+-------------------+
1 row in set (0.01 sec)
mysql> exit;
更多推荐



所有评论(0)