亚囡 发表于 2024-2-25 02:29:33

数据库mysql的四种安装方式(非常全面!)

一,仓库安装

1,使用rpm命令从指定的网址装包
​# rpm -ivhhttps://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm​https://img.jbzj.com/file_images/article/202402/2024022015300460.png
2,查看已经安装的仓库id和仓库名称,会发现多了以下几个仓库
MySQL Connectors Community; MySQL Tools Community;MySQL 8.0 Community Server;
# yum repolisthttps://img.jbzj.com/file_images/article/202402/2024022015300461.png
3,安装mysql软件
# dnf install mysql-server -yhttps://img.jbzj.com/file_images/article/202402/2024022015300462.png
4,运行mysql软件
# systemctl start mysqldhttps://img.jbzj.com/file_images/article/202402/2024022015300463.png
5,查看mysqld服务的状态
# systemctl status mysqldhttps://img.jbzj.com/file_images/article/202402/2024022015300464.png
6,在/var/log/mysqld.log目录下面查看数据库root的临时密码
# grep 'temporary password' /var/log/mysqld.loghttps://img.jbzj.com/file_images/article/202402/2024022015300565.png
7,使用临时密码登录数据库(密码和-p之间不能有空格)
# mysql -uroot -p' 9tJZ4JPtVa,)'https://img.jbzj.com/file_images/article/202402/2024022015300566.png
8,必须重置root用户的密码
要求密码至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为8个字符。密码和-p不能有空格隔开
mysql> alter user root@localhost identified by 'Admin123!';https://img.jbzj.com/file_images/article/202402/2024022015300567.png
9,退出数据库
mysql> exithttps://img.jbzj.com/file_images/article/202402/2024022015300568.png
10,使用新设置的密码登录数据库
# mysql -uroot -pAdmin123!https://img.jbzj.com/file_images/article/202402/2024022015300569.png
11,查看数据库
mysql> show databases;https://img.jbzj.com/file_images/article/202402/2024022015300670.png
卸载数据库软件
1,使用命令卸载mysql软件
# dnf remove mysql-server -yhttps://img.jbzj.com/file_images/article/202402/2024022015300671.png
2,查看是否卸载干净
# rpm -qa | grep mysqlhttps://img.jbzj.com/file_images/article/202402/2024022015300672.png
3,把没卸载干净的卸载完
# rpm -e mysql80-community-release-el9-1.noarchhttps://img.jbzj.com/file_images/article/202402/2024022015300673.png
4,清除日志文件
# rm -rf /var/lib/mysql /var/log/mysqld.loghttps://img.jbzj.com/file_images/article/202402/2024022015300674.png

二,本地安装

1,新建一个mysql目录,并切换到mydql目录下
# mkdir mysql # cd mysqlhttps://img.jbzj.com/file_images/article/202402/2024022015300675.png
2,下载rpm包
​# wgethttps://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar​https://img.jbzj.com/file_images/article/202402/2024022015300776.png
3,下载完成后是一个tar包,需要解包
# tar xf mysql-8.0.32-1.el9.x86_64.rpm-bundle.tarhttps://img.jbzj.com/file_images/article/202402/2024022015300777.png
4,解包后会生成许多rpm包
# llhttps://img.jbzj.com/file_images/article/202402/2024022015300778.png
5,安装mysql时会用到一些依赖包;安装依赖包(包之间有依赖,一起安装)
# rpm -ivh mysql-community-server-8.0.32-1.el9.x86_64.rpmmysql-community-client-8.0.32-1.el9.x86_64.rpm mysql-community-common-8.0.32-1.el9.x86_64.rpm mysql-community-icu-data-files-8.0.32-1.el9.x86_64.rpm mysql-community-client-plugins-8.0.32-1.el9.x86_64.rpmmysql-community-libs-8.0.32-1.el9.x86_64.rpmhttps://img.jbzj.com/file_images/article/202402/2024022015300779.png
6,启动mysqld服务
# systemctl start mysqldhttps://img.jbzj.com/file_images/article/202402/2024022015300780.png
7,查看服务状态
# systemctl status mysqldhttps://img.jbzj.com/file_images/article/202402/2024022015300881.png
8,查看数据库root的临时密码
# grep 'temporary password' /var/log/mysqld.loghttps://img.jbzj.com/file_images/article/202402/2024022015300882.png
9,使用临时密码登录数据库
# mysql -uroot -p'Lf+lN:jqO3;w'https://img.jbzj.com/file_images/article/202402/2024022015300883.png
10,设置新密码
要求密码至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为8个字符。
密码和-p不能有空格隔开,用单引号引起来
mysql> alter user root@localhost identified by 'Admin123!';https://img.jbzj.com/file_images/article/202402/2024022015300884.png
11,退出数据库
mysql> exithttps://img.jbzj.com/file_images/article/202402/2024022015300885.png
12,使用新密码登录
# mysql -uroot -p'Admin123!';https://img.jbzj.com/file_images/article/202402/2024022015300986.png
13,查看数据库
mysql> show databases;https://img.jbzj.com/file_images/article/202402/2024022015300987.png
卸载软件
1,卸载包,卸载时不需要加包名
# rpm -evh mysql-community-client-plugins mysql-community-common mysql-community-libs mysql-community-client mysql-community-icu-data-files mysql-community-serverhttps://img.jbzj.com/file_images/article/202402/2024022015300988.png
2,清除日志文件
# rm -rf /var/lib/mysql /var/log/mysqld.loghttps://img.jbzj.com/file_images/article/202402/2024022015300989.png

三,容器安装

1,如果之前安装过容器相关的包;卸载已有的包
# rm -rf /var/lib/mysql /var/log/mysqld.log# yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-enginehttps://img.jbzj.com/file_images/article/202402/2024022015300990.png
2,装容器所需要的依赖包
# dnf install -y yum-utils device-mapper-persistent-data lvm2https://img.jbzj.com/file_images/article/202402/2024022015300991.png
3,需要写容器的仓库;添加阿里云的仓库
​# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo​https://img.jbzj.com/file_images/article/202402/2024022015301092.png
4,查看目录/etc/yum.repos.d;会发现多了一个docker-ce.repo
# cd /etc/yum.repos.d## llhttps://img.jbzj.com/file_images/article/202402/2024022015301093.png
5,查看已经安装的仓库id和仓库名称,会发现多了1个仓库
# yum repolisthttps://img.jbzj.com/file_images/article/202402/2024022015301094.png
6,修改下载docker的网站,改为阿里云的(国内的比较快)
# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repohttps://img.jbzj.com/file_images/article/202402/2024022015301095.png
7,安装docker--ce时需要替换冲突软件包
# dnf install docker-ce --allowerasing -yhttps://img.jbzj.com/file_images/article/202402/2024022015301096.png
8,启动docker服务
# systemctl start dockerhttps://img.jbzj.com/file_images/article/202402/2024022015301097.png
9,查看docker服务状态
# systemctl status dockerhttps://img.jbzj.com/file_images/article/202402/2024022015301198.png
10,测试能否正常使用
# docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=123456 -d mysqlhttps://img.jbzj.com/file_images/article/202402/2024022015301199.png
# docker pshttps://img.jbzj.com/file_images/article/202402/20240220153011100.png
11,进到容器里面操作数据库
#docker exec -it mysqltest /bin/bashbash-4.4# mysql -uroot -p123456 https://img.jbzj.com/file_images/article/202402/20240220153011101.png
12,查看数据库
mysql> show databases;https://img.jbzj.com/file_images/article/202402/20240220153011102.png

四,源码安装

1,下载源码包
​# wgethttps://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.32.tar.gz--2023-02-10 09:14:15--https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.32.tar.gzResolving cdn.mysql.com (cdn.mysql.com)... 23.36.48.238Connecting to cdn.mysql.com (cdn.mysql.com)|23.36.48.238|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 436207624 (416M) Saving to: ‘mysql-boost-8.0.32.tar.gz.1'mysql-boost-8.0.32.tar.gz.1    100%[===================================================>] 416.00M5.33MB/s    in 74s    2023-02-10 09:15:30 (5.63 MB/s) - ‘mysql-boost-8.0.32.tar.gz.1' saved ​https://img.jbzj.com/file_images/article/202402/20240220153011103.png
2,添加用户和组:
# groupadd mysqlgroupadd: group 'mysql' already exists#useradd -r -g mysql -s /bin/false mysqluseradd: user 'mysql' already exists#https://img.jbzj.com/file_images/article/202402/20240220153012104.png
3,解压包:
# tar xvf mysql-boost-8.0.32.tar.gz.1https://img.jbzj.com/file_images/article/202402/20240220153012105.png
4,解压完成后会生成一堆文件在mysql-8.0.32目录下:
# lltotal 425992drwxr-xr-x. 32 7161 31415      4096 Dec 16 23:59 mysql-8.0.32-rw-r--r--.1 root root436207624 Dec 16 23:01 mysql-boost-8.0.32.tar.gz.1https://img.jbzj.com/file_images/article/202402/20240220153012106.png
5,切换到目录mysql-8.0.32下,可以查看到源码包里面所有的东西
# cd mysql-8.0.32/# lsboost         configure.cmake    include            libservices    packaging          share          testclientsclient          Docs               INSTALL            LICENSE      plugin             sql            unittestcmake         Doxyfile-ignored   libbinlogevents      man            README             sql-common   utilitiesCMakeLists.txtDoxyfile.in      libbinlogstandalonemysql-test   router             storage      viocomponents      doxygen_resourceslibchangestreams   MYSQL_VERSIONrun_doxygen.cmakestringsconfig.h.cmakeextra            libmysql             mysys          scripts            support-fileshttps://img.jbzj.com/file_images/article/202402/20240220153012107.png
6,安装编译器
# yum install gcc gcc-c++ cmake -yUpdating Subscription Management repositories.Unable to read consumer identityThis system is not registered with an entitlement server. You can use subscription-manager to register.MySQL Tools Community                                                                      1.3 kB/s | 2.6 kB   00:01   baseos                                                                                     2.7 MB/s | 2.7 kB   00:00   AppStream                                                                                  3.1 MB/s | 3.2 kB   00:00   Dependencies resolved.https://img.jbzj.com/file_images/article/202402/20240220153012108.png
7,安装编译过程中可能需要的一些库:
# yum install   cmake gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils openssl-devel ncurses-devel libtirpc rpcgen git-yUpdating Subscription Management repositories.Unable to read consumer identityThis system is not registered with an entitlement server. You can use subscription-manager to register.https://img.jbzj.com/file_images/article/202402/20240220153013109.png
8,安装包:
​# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/CRB/x86_64/os/Packages/libtirpc-devel-1.3.3-0.el9.x86_64.rpmRetrieving https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/CRB/x86_64/os/Packages/libtirpc-devel-1.3.3-0.el9.x86_64.rpmwarning: /var/tmp/rpm-tmp.xz3G2s: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEYVerifying...                        ################################# Preparing...                        ################################# Updating / installing...   1:libtirpc-devel-1.3.3-0.el9       ################################# ​https://img.jbzj.com/file_images/article/202402/20240220153013110.png
9,创建一个编译的目录:
# mkdir bldhttps://img.jbzj.com/file_images/article/202402/20240220153013111.png
# cd bldhttps://img.jbzj.com/file_images/article/202402/20240220153013112.png
10,编译(注意路径):
# cmake .. -DWITH_BOOST=../boost/boost_1_77_0/-- Running cmake version 3.20.2-- Found Git: /usr/bin/git (found version "2.31.1")https://img.jbzj.com/file_images/article/202402/20240220153013113.png
https://img.jbzj.com/file_images/article/202402/20240220153014114.png
11,编译
# makehttps://img.jbzj.com/file_images/article/202402/20240220153014115.png
12,安装:把编译的文件拷贝到对应的系统下的目录
# make installhttps://img.jbzj.com/file_images/article/202402/20240220153014116.png
13,切换到目录/usr/local/mysql下
# cd /usr/local/mysqlhttps://img.jbzj.com/file_images/article/202402/20240220153014117.png
14,创建目录 mysql-files 用来存储mysql的一些数据
# mkdir mysql-fileshttps://img.jbzj.com/file_images/article/202402/20240220153014118.png
15,修改此目录的所属者与所属组以及此目录的权限,防止mysql读不到,
# chown mysql:mysql mysql-files# chmod 750 mysql-fileshttps://img.jbzj.com/file_images/article/202402/20240220153015119.png
16,初始化数据库
# ./bin/mysqld --initialize --user=mysqlhttps://img.jbzj.com/file_images/article/202402/20240220153015120.png
17,开启lsl的加密
# ./bin/mysql_ssl_rsa_setuphttps://img.jbzj.com/file_images/article/202402/20240220153015121.png
18,获取临时密码
#grep 'temporary password' /var/log/mysqld.log2023-02-07T13:07:17.842453Z 6 A temporary password is generated for root@localhost: *2D):irrJ_!_https://img.jbzj.com/file_images/article/202402/20240220153015122.png
19,使用新密码登录
# mysql -uroot -p'Admin123!';https://img.jbzj.com/file_images/article/202402/20240220153015123.png
20,查看数据库
mysql> show databases;https://img.jbzj.com/file_images/article/202402/20240220153016124.png

总结

到此这篇关于数据库mysql的四种安装方式的文章就介绍到这了,更多相关mysql四种安装方式内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

来源:https://www.jb51.net/database/315983c0x.htm
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: 数据库mysql的四种安装方式(非常全面!)