查看ubuntu版本
1、下载安装包
https://downloads.mysql.com/archives/community/
Product Version: 5.7.44
Operating System: Linux - Generic
OS Version: All
2、解压安装包
tar -xvf mysql-5.7.44-linux-glibc2.12-x86_64.tar
得到:mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
mysql-test-5.7.44-linux-glibc2.12-x86_64.tar.gz
sudo tar -zxvf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
得到:mysql-5.7.44-linux-glibc2.12-x86_64
3、复制文件到指定目录
sudo mv mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local/mysql
4、需改用户归属
sudo chown $(whoami) /usr/local/mysql
5、初始化数据库
cd /usr/local/mysql
sudo bin/mysqld --initialize --user=mysql
提示:bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
6、安装libaio.so
sudo apt-get install libaio1
提示 软件包 libaio1 没有可安装候选
7、启用第三方源
sudo add-apt-repository universe
sudo apt-get update
sudo apt-get install libaio1
还是没有找到安装包
8、查看有没相关的包
apt search libaio
ubuntu@ubuntu-PowerEdge-R730xd:/usr/local/mysql$ apt search libaio
libaio-dev/noble-updates 0.3.113-6build1.1 amd64
Linux kernel AIO access library - development files
libaio1t64/noble-updates 0.3.113-6build1.1 amd64
Linux kernel AIO access library - shared library
9、安装libaio相关包
sudo apt-get install libaio-dev libaio1t64
再次sudo bin/mysqld --initialize --user=mysql
还是缺libaio
10、使用源码安装libaio
下载源码libaio-0.3.112.tar.gz
git clone https://gitee.com/src-oepkgs/libaio.git
解压源码包
tar zxvf libaio-0.3.112.tar.gz
编译
cd libaio-0.3.112/
make
sudo make install
11、重新初始化
sudo bin/mysqld --initialize --user=mysql
提示:
2025-06-13T09:38:18.808416Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-06-13T09:38:18.811559Z 0 [ERROR] Fatal error: Can't change to run as user 'mysql' ; Please check that the user exists!
2025-06-13T09:38:18.811580Z 0 [ERROR] Aborting
12、添加用户
sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql
13、重新初始化
sudo bin/mysqld --initialize --user=mysql
2025-06-13T09:42:20.239574Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-06-13T09:42:20.375502Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-06-13T09:42:20.401777Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-06-13T09:42:20.455024Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b374940b-483a-11f0-a68a-90b11c1c28ce.
2025-06-13T09:42:20.455401Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-06-13T09:42:21.804231Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-06-13T09:42:21.804244Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-06-13T09:42:21.807195Z 0 [Warning] CA certificate ca.pem is self signed.
2025-06-13T09:42:22.032412Z 1 [Note] A temporary password is generated for root@localhost: rm&smlwKy1Tn
这个加深颜色的就是初始密码
14、复制配置文件:
sudo cp support-files/mysql.server /etc/init.d/mysql
sudo chmod +x /etc/init.d/mysql
15、设置环境变量:
在~/.bashrc或/etc/profile中添加以下行:
export PATH=/usr/local/mysql/bin:$PATH
然后运行source ~/.bashrc或重新登录。
16、启动MySQL服务:
sudo /etc/init.d/mysql start
17、缺少相关库
ubuntu@ubuntu-PowerEdge-R730xd:~$ mysql
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
创建符号链接
sudo ln -s /usr/lib/x86_64-linux-gnu/libncurses.so.6.4 /usr/lib/x86_64-linux-gnu/libncurses.so.5
还是缺少libtinfo
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
创建符号链接
sudo ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4 /usr/lib/x86_64-linux-gnu/libtinfo.so.5
17、设置root密码(如果需要):
ubuntu@ubuntu-PowerEdge-R730xd:/opt$ mysql -u root -p
Enter password:rm&smlwKy1Tn
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.44
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 databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'test1234';
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
18、查看mysql服务
ps -ef|grep mysql
root 30927 1 0 18:06 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/ubuntu-PowerEdge-R730xd.pid
mysql 31011 30927 2 18:06 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=ubuntu-PowerEdge-R730xd.err --pid-file=/usr/local/mysql/data/ubuntu-PowerEdge-R730xd.pid
ubuntu 31041 25839 0 18:06 pts/0 00:00:00 grep --color=auto mysql
至此安装OK