|
一,仓库安装
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,退出数据库
10,使用新设置的密码登录数据库- [root@localhost yum.repos.d]# mysql -uroot -pAdmin123!
复制代码
11,查看数据库
卸载数据库软件
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,退出数据库
12,使用新密码登录- [root@localhost mysql]# mysql -uroot -p'Admin123!';
复制代码
13,查看数据库
卸载软件
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/bashbash-4.4# mysql -uroot -p123456
复制代码
12,查看数据库
四,源码安装
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.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) [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 mysqlgroupadd: group 'mysql' already exists[root@localhost yum.repos.d]# useradd -r -g mysql -s /bin/false mysqluseradd: 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]# lltotal 425992drwxr-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]# lsboost configure.cmake include libservices packaging share testclientsclient Docs INSTALL LICENSE plugin sql unittestcmake Doxyfile-ignored libbinlogevents man README sql-common utilitiesCMakeLists.txt Doxyfile.in libbinlogstandalone mysql-test router storage viocomponents doxygen_resources libchangestreams MYSQL_VERSION run_doxygen.cmake stringsconfig.h.cmake extra libmysql mysys scripts support-files
复制代码
6,安装编译器- [root@localhost mysql-8.0.32]# 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.
复制代码
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 -yUpdating Subscription Management repositories.Unable to read consumer identityThis 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.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... ################################# [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.log2023-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的四种安装方式的文章就介绍到这了,更多相关mysql四种安装方式内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
来源:https://www.jb51.net/database/315983c0x.htm
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作! |
|