网址:MySQL
下载(环境准备):
(2-5点击此处,然后选择合适的版本)
1.linux在线YUM仓库
下载/安装:
wget https://repo.mysql.com//mysql84-community-release-el9-1.noarch.rpm
rpm -i https://repo.mysql.com//mysql84-community-release-el9-1.noarch.rpm
查看: dnf repolist
安装软件包: dnf install mysql-server
查看安装的mysql: rpm -qa | grep mysql
启用服务: systemctl start mysqld
查看服务状态: systemctl status mysqld
登录: mysql -uroot -p (这里用root用户,-p指密码 )
查看临时密码: grep password /var/log/mysqld.log
修改密码: alter user a’用户’@’用户名’ identified by ‘密码’;
查看: show databases;
删除清理: dnf remove mysql-server -y
m -rf /var/lib/mysql
rm -rf /var/log/mysqld.log
userdel -r mysql
2.二进制本地
下载:
wget https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.3-1.el9.x86_64.rpmbundle.tar
解压: tar xf mysql-8.4.3-1.el9.x86_64.rpm-bundle.tar
查看: ll mysql-*
安装: dnf localinstall mysql-community-server-8.4.3-1.el9.x86_64.rpm
查看安装的东西: rpm -qa | grep mysql
启用服务: systemctl start mysqld
查看服务状态: systemctl status mysqld
删除清理: dnf remove mysql-server -y
m -rf /var/lib/mysql
rm -rf /var/log/mysqld.log
userdel -r mysql
3.容器平台
安装工具,dnf的一个插件: dnf -y install dnf-plugins-core
添加Docker仓库:
dnf config-manager --add-repo https://download.docker.com/linux/rhel/dockerce.repo
安装Docker相关软件:
dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
启动Docker服务: systemctl enable --now docker
查询MySQL镜像: docker search mysql
下载mysql-8.4.3: docker pull mysql:8.4.3
查看: docker images
启动容器:
docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.4.3
查看并测试: docker ps
访问: docker exec -it mysqltest /bin/bash
mysql -uroot -p
退出: exit
删除清理:
docker stop mysqltest
docker rm mysqltest
docker ps -a
4.源码部署
我们在根目录中创建mysql目录,方便操作
mkdir /mysql
mv mysql-8.4.3.tar.gz /mysql
cd /mysql
解压:
tar xf mysql-8.4.3.tar.gz
cd mysql-8.4.3/
创建用户,修改目录权限:
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
chmod 777 /mysql/ -R
安装需要的软件:
mkdir bld
cd bld
dnf install cmake openssl-devel ncurses-devel rpcgen gcc-toolset-12-gcc gcc-toolset-12- gcc-c++ gcc-toolset-12-binutils gcc-toolset-12- annobin-annocheck gcc-toolset-12-annobin- plugin-gcc
rpm -i https://yum.oracle.com/repo/OracleLinux/OL9/codeready/builder/x86_64/getPackage/libtirpc -devel-1.3.3-9.el9.x86_64.rpm
配置并编译:
cmake ..
make
make install
cd /usr/local/mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize --user=mysql
bin/mysqld_safe --user=mysql &
登录测试: mysql -S /tmp/mysql.sock -uroot -p
改密码: alter user a’用户’@’用户名’ identified by ‘密码’;
查看: show databases;
删除清理: make clean
rm -rf /usr/local/mysql/
5.windows
启动mysql:
指令验证mysql是否正常使用