目录
一、仓库安装
1、查看文件
2、下载安装包
3、 查看Mysql登录密码
4、登录Mysql
5、 修改密码
6、重新登录
7、查看数据库
8、读表命令
9、卸载数据库软件
二、本地安装
1、创建mysql文件夹
2、下载安装包
3、解压缩包
4、安装所需要的依赖包
5、重启mysql
6、查看mysql密码
7、修改密码
8、卸载 数据库安装包
三、容器安装
1、卸载容器
2、下载安装包
3、添加阿里云仓库
4、查看仓库路径
5、使用sed命令将下载路径更换成阿里云路径
6、安装docker-ce
7、启动docker服务
8、测试docker是否正常使用
9、进入dockers,登录mysql
四、源码安装
1、建立本地源
2、·建立网络源(Redhat9暂时无公开的网络源,暂不可配置,其他发行版本可自行选择对应网源仓库)
阿里云网络源,aliyun的镜像站:https;//mirrors.aliyun.com/
[root@localhost ~]# rpm -ivh https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm
[root@localhost ~]# dnf install mysql-server -y
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
[root@localhost ~]# cat /var/log/mysqld.log
[root@localhost ~]# grep password /var/log/mysqld.log
[root@localhost ~]# mysql -uroot -p'dlKmpqd;K0#2'
mysql> alter user root@localhost identified by 'Admin123!';
登录之后必须先修改用户密码,默认密码策略要求密码至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为8个字符。
[root@localhost ~]# mysql -uroot -pAdmin123!
mysql> show databases;
mysql> select * from mysql.user;
mysql> select user,host,authentication_string from mysql.user;
[root@localhost ~]# dnf remove mysql-server -y
[root@localhost ~]# rpm -e mysql80-community-release
[root@localhost ~]# rm -rf /var/lib/mysql/ /var/log/mysqld.log
[root@localhost ~]# mkdir mysql //创建mysql文件夹
[root@localhost ~]# cd mysql/ //进入该文件夹
[root@localhost mysql]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar
[root@localhost mysql]# tar xf mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar
[root@localhost mysql]# dnf localinstall 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
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl status mysqld
[root@localhost mysql]# grep password /var/log/mysqld.log
[root@localhost mysql]# mysql -uroot -p'Oh/2oTpyqHdw'
mysql> alter user root@localhost identified by 'Admin123';
#查看数据库安装包
[root@localhost mysql]# rpm -qa | grep mysql
#卸载[root@localhost mysql]# rpm -evh mysql-community-server-8.0.32-1.el9.x86_64
[root@localhost mysql]# rpm -evh mysql-community-client-plugins-8.0.32-1.el9.x86_64 mysql-community-common-8.0.32-1.el9.x86_64 mysql-community-libs-8.0.32-1.el9.x86_64 mysql-community-client-8.0.32-1.el9.x86_64 mysql-community-icu-data-files-8.0.32-1.el9.x86_64
[root@localhost mysql]# rm -rf /var/lib/mysql/ /var/log/mysql.log
[root@localhost ~]# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
[root@localhost ~]# dnf install -y yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
[root@localhost ~]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
[root@localhost ~]# dnf install docker-ce --allowerasing -y
[root@localhost yum.repos.d]# systemctl start docker
[root@localhost yum.repos.d]# systemctl status docker
#访问容器数据库
[root@localhost ~]# docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=123456 -d mysql
[root@localhost ~]# docker ps
#进入mysql
[root@localhost ~]# docker exec -it mysqltest /bin/bash#设置密码
bash-4.4# mysql -uroot -p123456
Enter password:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)mysql> exit
Bye
bash-4.4# exit
exit
[root@kongd ~]# mkdir /media/cdrom
#将本地光盘挂载至本地目录/media/cdrom下
[root@kongd ~]# mount /dev/cdrom / media/cdrom[root@kongd ~]# cat /etc / yum.repos.d/rhel9.repo
[RHEL9-Baseos]
name=RHEL9-Baseos
baseur1=file : / / / media/cdrom/Baseosgpgcheck=0
#apgcheck=1 #如果gpgcheck为1,需要写秘钥文件路径
#gpgkey=file : / / /etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial[RHEL9-Appstream]
name=RHEL9-Appstream
baseur1=file: / / / media/cdrom / Appstreamgpgcheck=0
#gpgcheck=1
#gpgkey=file :/ l/etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficia7[root@kongd ~]# yum repolist
#验i证能否装包成功
[root@master ~]# yum insta11 bind-utils -y
[root@localhost yum.repos.d]# cat aliyun.repo
[aliyun-app]
name=aliyun-appsteam
baseurl=https : //mirrors.aliyun.com/centos-stream/9-stream/AppStream/x86_64/osgpgcheck=0
[aliyun-base]
name=aliyun-baseos
baseurl=https : / /mirrors.aliyun.com/centos-stream/9-stream/BaseOS/x86_64/os/gpgcheck=0
## 参考官方文档 https://dev.mysql.com/doc/refman/8.0/en/installing-source-distribution.html
[root@localhost ~]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.34.tar.gz
#添加用户和组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql
#开始源码安装
[root@localhost ~]# tar xvf mysql-boost-8.0.34.tar.gz
[root@localhost ~]# yum install gcc gcc-c++ cmake -y
[root@localhost ~]# yum install cmake gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils openssl-devel ncurses-devel libtirpc rpcgen git -y
[root@localhost ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/CRB/x86_64/os/Packages/libtirpc-devel-1.3.3-2.el9.x86_64.rpm
[root@localhost ~]# cd mysql-8.0.34/
[root@localhost mysql-8.0.32]# mkdir bld
[root@localhost mysql-8.0.32]# cd bld
[root@localhost bld]# cmake .. -DWITH_BOOST=../boost/boost_1_77_0/
[root@localhost bld]# make ########该过程很久,请耐心等待
[root@localhost bld]# make install
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# mkdir mysql-files
[root@localhost mysql]# chown mysql:mysql mysql-files
[root@localhost mysql]# chmod 750 mysql-files
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql
[root@localhost mysql]# ./bin/mysql_ssl_rsa_setup
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql &
#源码安装未生成该文件,临时密码在初始化时屏幕上有输出
[root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log
[root@localhost mysql]# ./bin/mysql -uroot -p
Enter password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin123!';
mysql> show databases;
mysql> exit#停止mysql服务
[root@localhost mysql]# ./bin/mysqladmin -uroot -pAdmin123! shutdown# Next command is optional
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql.server
[root@localhost mysql]# systemctl daemon-reload
[root@localhost mysql]# systemctl start mysql