正文
一、安装 libaio
依赖
feng@feng:~/software/dev$ apt-cache search libaio libaio1 - Linux kernel AIO access library - shared library libaio-dev - Linux kernel AIO access library - development files
feng@feng:~/software/dev$ sudo apt install libaio1 [sudo] feng 的密码: 正在读取软件包列表... 完成 正在分析软件包的依赖关系树... 完成 正在读取状态信息... 完成 下列【新】软件包将被安装: libaio1 升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 36 个软件包未被升级。 需要下载 7,176 B 的归档。 解压缩后会消耗 37.9 kB 的额外空间。 获取:1 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 libaio1 amd64 0.3.112-13build1 [7,176 B] 已下载 7,176 B,耗时 1秒 (8,818 B/s) 正在选中未选择的软件包 libaio1:amd64。 (正在读取数据库 ... 系统当前共安装有 180816 个文件和目录。) 准备解压 .../libaio1_0.3.112-13build1_amd64.deb ... 正在解压 libaio1:amd64 (0.3.112-13build1) ... 正在设置 libaio1:amd64 (0.3.112-13build1) ... 正在处理用于 libc-bin (2.35-0ubuntu3.1) 的触发器 ...
二、解压 mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
tar -xf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
查看解压的文件
文件夹 | 文件夹内容 |
bin | mysqld 服务端、客户端和配套的程序 |
docs | MySQL 文档 |
man | Unix 文档(可以使用 man 命令调出) |
include | 包含头(header)文件 |
lib | 库 |
share | 数据库安装相关的错误信息,术语、SQL |
support-files | 各种各样的支持文件 |
三、安装
feng@feng:~/software/dev/mysql-8.0.28-linux-glibc2.12-x86_64$ sudo groupadd mysql [sudo] feng 的密码: feng@feng:~/software/dev/mysql-8.0.28-linux-glibc2.12-x86_64$ sudo useradd -r -g mysql -s /bin/false mysql feng@feng:~/software/dev/mysql-8.0.28-linux-glibc2.12-x86_64$ cd /usr/local/ feng@feng:/usr/local$ sudo ln -s /home/feng/software/dev/mysql-8.0.28-linux-glibc2.12-x86_64 mysql feng@feng:/usr/local$ ls bin etc games include lib man mysql sbin share src feng@feng:/usr/local$ cd mysql feng@feng:/usr/local/mysql$ ls bin docs include lib LICENSE man README share support-files feng@feng:/usr/local/mysql$ mkdir mysql-files feng@feng:/usr/local/mysql$ sudo chown mysql:mysql mysql-files feng@feng:/usr/local/mysql$ sudo chmod 750 mysql-files feng@feng:/usr/local/mysql$ ./bin/mysqld --initialize --user=root 2022-11-11T03:11:43.390174Z 0 [System] [MY-013169] [Server] /home/feng/software/dev/mysql-8.0.28-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.28) initializing of server in progress as process 19970 2022-11-11T03:11:43.390999Z 0 [Warning] [MY-010122] [Server] One can only use the --user switch if running as root 2022-11-11T03:11:43.454295Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-11-11T03:11:53.151407Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2022-11-11T03:12:14.146844Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /Vfe3n/+qdm6
注意:前面执行的命令里头 --user=root
,官方文档里头其实不是这么写的,而是 --user=mysql
,但我在ubuntu中,老是出错,就改成了 root。并且接下来的所有命令都是通过 root 用户执行的。亲测可行。
四、编辑systemd文件
vim /usr/lib/systemd/system/mysql.service
[Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=root Group=root # Have mysqld write its state to the systemd notify socket Type=notify # Disable service start and stop timeout logic of systemd for mysqld service. TimeoutSec=0 # Start main service ExecStart=/usr/local/mysql/bin/mysqld --user=root # Sets open_files_limit LimitNOFILE = 10000 Restart=on-failure RestartPreventExitStatus=1 # Set environment variable MYSQLD_PARENT_PID. This is required for restart. Environment=MYSQLD_PARENT_PID=1 PrivateTmp=false
systemctl daemon-reload systemctl restart mysql
启动成功
五、解决登录问题
启动完成之后,我遇到了一个报错,如下所示:
root@feng:/usr/local/mysql/bin# ./mysql -u root@localhost -p ./mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
解决方法如下:
root@feng:/usr/local/mysql/bin# find /usr/ -name 'libtinfo*' /usr/share/doc/libtinfo6 /usr/lib/x86_64-linux-gnu/libtinfo.so.6.3 /usr/lib/x86_64-linux-gnu/libtinfo.so /usr/lib/x86_64-linux-gnu/libtinfo.a /usr/lib/x86_64-linux-gnu/libtinfo.so.6 root@feng:/usr/local/mysql/bin# ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6.3 /usr/lib/x86_64-linux-gnu/libtinfo.so.5
解决思路就是:找到操作系统里的 libtinfo.so.*
的位置,然后建立一个软链接到对应目录下的 libtinfo.so.5
已解决
六、修改初始密码
通过客户端连进去之后,执行下面的sql,修改密码:
alter user user() identified by '123456'
七、创建 'root'@'%' 用户
mysql> create user 'root'@'%' identified by '123456'; Query OK, 0 rows affected (0.12 sec) mysql> grant all on *.* to 'root'@'%'; Query OK, 0 rows affected (0.10 sec) mysql> flush privileges; Query OK, 0 rows affected (0.06 sec) mysql>
出处。