0


【数据库】 mysql的四种安装方式

MySQL 安装部署

一,仓库安装

1,使用rpm命令从指定的网址装包

​
[root@localhost yum.repos.d]# rpm -ivh  https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm

​

**2,查看已经安装的仓库id和仓库名称,会发现多了以下几个仓库 **

** MySQL Connectors Community; MySQL Tools Community ;MySQL 8.0 Community Server;**

[root@localhost yum.repos.d]# yum repolist

3,安装mysql软件

[root@wangjingjing yum.repos.d]# dnf install mysql-server -y

4,运行mysql软件

[root@localhost yum.repos.d]# systemctl start mysqld

5,查看mysqld服务的状态

[root@wangjingjing yum.repos.d]# systemctl status mysqld

6,在/var/log/mysqld.log目录下面查看数据库root的临时密码

[root@localhost yum.repos.d]# grep 'temporary password' /var/log/mysqld.log

7,使用临时密码登录数据库(密码和-p之间不能有空格)

[root@localhost yum.repos.d]# mysql -uroot -p' 9tJZ4JPtVa,)'

8,必须重置root用户的密码

要求密码至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为8个字符。密码和-p不能有空格隔开

mysql> alter user root@localhost identified by 'Admin123!';

9,退出数据库

mysql> exit

10,使用新设置的密码登录数据库

[root@localhost yum.repos.d]# mysql -uroot -pAdmin123!

11,查看数据库

mysql> show databases;

卸载数据库软件

1,使用命令卸载mysql软件

[root@localhost yum.repos.d]# dnf remove mysql-server -y

2,查看是否卸载干净

[root@localhost yum.repos.d]# rpm -qa | grep mysql

3,把没卸载干净的卸载完

[root@localhost yum.repos.d]# rpm -e mysql80-community-release-el9-1.noarch

4,清除日志文件

[root@localhost yum.repos.d]# rm -rf /var/lib/mysql /var/log/mysqld.log

二,本地安装

1,新建一个mysql目录,并切换到mydql目录下

[root@localhost yum.repos.d]# mkdir mysql

[root@localhost yum.repos.d]# cd mysql

2,下载rpm包

​
[root@localhost mysql]# wget  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar

​

3,下载完成后是一个tar包,需要解包

[root@localhost mysql]# tar xf mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar

4,解包后会生成许多rpm包

[root@localhost mysql]# ll

5,安装mysql时会用到一些依赖包;安装依赖包(包之间有依赖,一起安装)

[root@localhost mysql]# rpm -ivh mysql-community-server-8.0.32-1.el9.x86_64.rpm  mysql-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.rpm  mysql-community-libs-8.0.32-1.el9.x86_64.rpm

6,启动mysqld服务

[root@localhost mysql]# systemctl start mysqld

7,查看服务状态

[root@localhost mysql]# systemctl status mysqld

8,查看数据库root的临时密码

[root@localhost yum.repos.d]# grep 'temporary password' /var/log/mysqld.log

9,使用临时密码登录数据库

[root@localhost mysql]# mysql -uroot -p'Lf+lN:jqO3;w'

10,设置新密码

要求密码至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为8个字符。

密码和-p不能有空格隔开,用单引号引起来

mysql> alter user root@localhost identified by 'Admin123!';

11,退出数据库

mysql> exit

12,使用新密码登录

[root@localhost mysql]# mysql -uroot -p'Admin123!';

13,查看数据库

mysql> show databases;

卸载软件

1,卸载包,卸载时不需要加包名

[root@localhost mysql]# rpm -evh mysql-community-client-plugins mysql-community-common mysql-community-libs mysql-community-client mysql-community-icu-data-files mysql-community-server

2,清除日志文件

[root@localhost yum.repos.d]# rm -rf /var/lib/mysql /var/log/mysqld.log

三,容器安装

1,如果之前安装过容器相关的包;卸载已有的包

[root@localhost mysql]# rm -rf /var/lib/mysql /var/log/mysqld.log

[root@localhost mysql]# yum remove docker \

docker-client \

docker-client-latest \

docker-common \

docker-latest \

docker-latest-logrotate \

docker-logrotate \

docker-engine

2,装容器所需要的依赖包

[root@localhost mysql]# dnf install -y yum-utils device-mapper-persistent-data lvm2

3,需要写容器的仓库;添加阿里云的仓库

​
[root@localhost mysql]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

​

4,查看目录/etc/yum.repos.d;会发现多了一个docker-ce.repo

[root@localhost mysql]# cd /etc/yum.repos.d

[root@localhost yum.repos.d]#

[root@localhost yum.repos.d]# ll

5,查看已经安装的仓库id和仓库名称,会发现多了1个仓库

[root@localhost yum.repos.d]# yum repolist

6,修改下载docker的网站,改为阿里云的(国内的比较快)

[root@localhost yum.repos.d]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo

7,安装docker--ce时需要替换冲突软件包

[root@localhost yum.repos.d]# dnf install docker-ce --allowerasing -y

8,启动docker服务

[root@localhost yum.repos.d]# systemctl start docker

9,查看docker服务状态

[root@localhost yum.repos.d]# systemctl status docker

10,测试能否正常使用

[root@localhost yum.repos.d]# docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=123456 -d mysql

[root@localhost yum.repos.d]# docker ps

11,进到容器里面操作数据库

[root@localhost yum.repos.d]#  docker exec -it mysqltest /bin/bash

bash-4.4# mysql -uroot -p123456 

12,查看数据库

mysql> show databases;

四,源码安装

1,下载源码包

​
[root@localhost yum.repos.d]# wget  https://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.gz

Resolving cdn.mysql.com (cdn.mysql.com)... 23.36.48.238

Connecting to cdn.mysql.com (cdn.mysql.com)|23.36.48.238|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 436207624 (416M) [application/x-tar-gz]

Saving to: ‘mysql-boost-8.0.32.tar.gz.1’

mysql-boost-8.0.32.tar.gz.1    100%[===================================================>] 416.00M  5.33MB/s    in 74s    

2023-02-10 09:15:30 (5.63 MB/s) - ‘mysql-boost-8.0.32.tar.gz.1’ saved [436207624/436207624]

​

2,添加用户和组:

[root@localhost yum.repos.d]# groupadd mysql

groupadd: group 'mysql' already exists

[root@localhost yum.repos.d]#  useradd -r -g mysql -s /bin/false mysql

useradd: user 'mysql' already exists

[root@localhost yum.repos.d]#

3,解压包:

[root@localhost mysql-source]# tar xvf mysql-boost-8.0.32.tar.gz.1

4,解压完成后会生成一堆文件在mysql-8.0.32目录下:

[root@localhost mysql-source]# ll

total 425992

drwxr-xr-x. 32 7161 31415      4096 Dec 16 23:59 mysql-8.0.32

-rw-r--r--.  1 root root  436207624 Dec 16 23:01 mysql-boost-8.0.32.tar.gz.1

5,切换到目录mysql-8.0.32下,可以查看到源码包里面所有的东西

[root@localhost mysql-source]# cd mysql-8.0.32/

[root@localhost mysql-8.0.32]# ls

boost           configure.cmake    include              libservices    packaging          share          testclients

client          Docs               INSTALL              LICENSE        plugin             sql            unittest

cmake           Doxyfile-ignored   libbinlogevents      man            README             sql-common     utilities

CMakeLists.txt  Doxyfile.in        libbinlogstandalone  mysql-test     router             storage        vio

components      doxygen_resources  libchangestreams     MYSQL_VERSION  run_doxygen.cmake  strings

config.h.cmake  extra              libmysql             mysys          scripts            support-files

6,安装编译器

[root@localhost mysql-8.0.32]# yum install gcc gcc-c++ cmake -y

Updating Subscription Management repositories.

Unable to read consumer identity

This 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.

7,安装编译过程中可能需要的一些库:

[root@localhost mysql-8.0.32]# yum install   cmake gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils openssl-devel ncurses-devel libtirpc rpcgen git  -y

Updating Subscription Management repositories.

Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

8,安装包:

​
[root@localhost mysql-8.0.32]# 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.rpm

Retrieving https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/CRB/x86_64/os/Packages/libtirpc-devel-1.3.3-0.el9.x86_64.rpm

warning: /var/tmp/rpm-tmp.xz3G2s: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY

Verifying...                          ################################# [100%]

Preparing...                          ################################# [100%]

Updating / installing...

   1:libtirpc-devel-1.3.3-0.el9       ################################# [100%]

​

9,创建一个编译的目录:

[root@localhost mysql-8.0.32]# mkdir bld

[root@localhost mysql-8.0.32]# cd bld

10,编译(注意路径):

[root@localhost bld]# cmake .. -DWITH_BOOST=../boost/boost_1_77_0/

-- Running cmake version 3.20.2

-- Found Git: /usr/bin/git (found version "2.31.1")

11,编译

[root@localhost bld]# make

12,安装:把编译的文件拷贝到对应的系统下的目录

[root@localhost bld]# make install

13,切换到目录/usr/local/mysql下

[root@localhost bld]# cd /usr/local/mysql

14,创建目录 mysql-files 用来存储mysql的一些数据

[root@localhost mysql]# mkdir mysql-files

15,修改此目录的所属者与所属组以及此目录的权限,防止mysql读不到,

[root@localhost mysql]# chown mysql:mysql mysql-files

[root@localhost mysql]# chmod 750 mysql-files

16,初始化数据库

[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql

17,开启lsl的加密

[root@localhost mysql]# ./bin/mysql_ssl_rsa_setup

18,获取临时密码

[root@localhost mysql]#  grep 'temporary password' /var/log/mysqld.log

2023-02-07T13:07:17.842453Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: *2D):irrJ_!_

19,使用新密码登录

[root@localhost mysql]# mysql -uroot -p'Admin123!';

20,查看数据库

mysql> show databases;


本文转载自: https://blog.csdn.net/weixin_48814356/article/details/128973023
版权归原作者 小胖鲸~ 所有, 如有侵权,请联系我们删除。

“【数据库】 mysql的四种安装方式”的评论:

还没有评论