目录MySQL 在 Centos 7环境安装CentOS 7.6 安装 MySQL 5.7 完整流程第一步环境准备避免冲突第二步获取并安装 MySQL 官方 YUM 仓库第三步安装 MySQL 服务器确实是否安装成功第四步启动并检查 MySQL 服务登陆重启mysql服务设置开机启动[可以不设]配置my.cnfMySQL 在 Centos 7环境安装如果是其他环境下可以借助ai或者其他博客进行安装执行的操作说明• 安装与卸载中用户全部切换成为root一旦安装普通用户能使用的• 初期练习mysql不进行用户管理全部使用root进行尽快适应mysql语句后面学了用户管 理在考虑新建普通用户CentOS 7.6 安装 MySQL 5.7 完整流程第一步环境准备避免冲突CentOS 7 系统默认预装了 MariaDB 库与 MySQL 直接冲突必须先行卸载。# 检查系统是否有 mariadb 相关的包rpm -qa | grep mariadb# 如果上一步有输出则执行卸载若无输出可跳过此步sudo yum remove mariadb-libs这一步至关重要可以避免在后续安装中出现文件冲突的错误第二步获取并安装 MySQL 官方 YUM 仓库这是最关键的一步需要下载正确的 RPM 包来添加 MySQL 源。# 1. 下载 MySQL 5.7 的官方仓库 RPM 包wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm# 2. 安装这个 RPM 包将 MySQL 的官方 YUM 源添加到你的系统中sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm注意若wget命令提示未找到请先运行sudo yum install -y wget进行安装第三步安装 MySQL 服务器添加完源之后就可以像安装普通软件一样使用yum轻松安装了。sudo yum install -y mysql-community-server如果在安装过程中遇到GPG 密钥验证失败的错误无需担心这是因为 MySQL 官方在 2023 年更新了 GPG 密钥按以下步骤导入新密钥后重新执行安装命令即可# 导入新的 MySQL GPG 密钥2022 年之后的版本 sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 # 重新安装 MySQL 服务器 sudo yum install -y mysql-community-server确实是否安装成功[rootiZ5waahoxw3q2bZ ~]# ls /etc/my.cnf /etc/my.cnf [rootiZ5waahoxw3q2bZ ~]# which mysqld /usr/sbin/mysqld [rootiZ5waahoxw3q2bZ ~]# which mysql /usr/bin/mysqlwhich mysqld要确保mysql服务端的程序要有which mysql要确保有mysql这样的客户端第四步启动并检查 MySQL 服务[rootiZ5waahoxw3q2bZ ~]# systemctl start mysqld [rootiZ5waahoxw3q2bZ ~]# ps ajx | grep mysqld 1 29678 29677 29677 ? -1 Sl 27 0:00 /usr/sbin/mysqld --daemonize --pid-file/var/run/mysqld/mysqld.pid 28738 29728 29727 28738 pts/1 29727 S 0 0:00 grep --colorauto mysqld查看mysql对应服务端口号[rootiZ5waahoxw3q2bZ ~]# netstat -nltp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1149/sshd tcp6 0 0 :::3306 :::* LISTEN 29678/mysqld登陆登陆发现登陆不上去[rootiZ5waahoxw3q2bZ ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user rootlocalhost (using password: YES)[rootiZ5waahoxw3q2bZ ~]# systemctl start mysqld # 打开mysql配置文件 [rootiZ5waahoxw3q2bZ ~]# vim /etc/my.cnf在[mysqld]最后一栏配置(不知道是什么就放在配置文件最后) 加入: skip-grant-tables 选项, 并保存退出重启mysql服务[rootiZ5waahoxw3q2bZ ~]# systemctl restart mysqld # 重启mysql服务[rootiZ5waahoxw3q2bZ ~]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.44 MySQL Community Server (GPL) Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type help; or \h for help. Type \c to clear the current input statement. mysql设置开机启动[可以不设][rootiZ5waahoxw3q2bZ ~]# systemctl enable mysqld [rootiZ5waahoxw3q2bZ ~]# systemctl daemon-reload配置my.cnf配置一下my.conf,主要是数据库客户端和服务器的编码格式port3306; character-set-serverutf8 default-storage-engineinnodb[rootiZ5waahoxw3q2bZ ~]# vim /etc/my.cnf重启[rootiZ5waahoxw3q2bZ ~]# systemctl restart mysqld[rootiZ5waahoxw3q2bZ ~]# netstat -nltp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1149/sshd tcp6 0 0 :::3306 :::* LISTEN 704/mysqld感谢你的观看启动我们下次再见
MySQl安装
目录MySQL 在 Centos 7环境安装CentOS 7.6 安装 MySQL 5.7 完整流程第一步环境准备避免冲突第二步获取并安装 MySQL 官方 YUM 仓库第三步安装 MySQL 服务器确实是否安装成功第四步启动并检查 MySQL 服务登陆重启mysql服务设置开机启动[可以不设]配置my.cnfMySQL 在 Centos 7环境安装如果是其他环境下可以借助ai或者其他博客进行安装执行的操作说明• 安装与卸载中用户全部切换成为root一旦安装普通用户能使用的• 初期练习mysql不进行用户管理全部使用root进行尽快适应mysql语句后面学了用户管 理在考虑新建普通用户CentOS 7.6 安装 MySQL 5.7 完整流程第一步环境准备避免冲突CentOS 7 系统默认预装了 MariaDB 库与 MySQL 直接冲突必须先行卸载。# 检查系统是否有 mariadb 相关的包rpm -qa | grep mariadb# 如果上一步有输出则执行卸载若无输出可跳过此步sudo yum remove mariadb-libs这一步至关重要可以避免在后续安装中出现文件冲突的错误第二步获取并安装 MySQL 官方 YUM 仓库这是最关键的一步需要下载正确的 RPM 包来添加 MySQL 源。# 1. 下载 MySQL 5.7 的官方仓库 RPM 包wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm# 2. 安装这个 RPM 包将 MySQL 的官方 YUM 源添加到你的系统中sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm注意若wget命令提示未找到请先运行sudo yum install -y wget进行安装第三步安装 MySQL 服务器添加完源之后就可以像安装普通软件一样使用yum轻松安装了。sudo yum install -y mysql-community-server如果在安装过程中遇到GPG 密钥验证失败的错误无需担心这是因为 MySQL 官方在 2023 年更新了 GPG 密钥按以下步骤导入新密钥后重新执行安装命令即可# 导入新的 MySQL GPG 密钥2022 年之后的版本 sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 # 重新安装 MySQL 服务器 sudo yum install -y mysql-community-server确实是否安装成功[rootiZ5waahoxw3q2bZ ~]# ls /etc/my.cnf /etc/my.cnf [rootiZ5waahoxw3q2bZ ~]# which mysqld /usr/sbin/mysqld [rootiZ5waahoxw3q2bZ ~]# which mysql /usr/bin/mysqlwhich mysqld要确保mysql服务端的程序要有which mysql要确保有mysql这样的客户端第四步启动并检查 MySQL 服务[rootiZ5waahoxw3q2bZ ~]# systemctl start mysqld [rootiZ5waahoxw3q2bZ ~]# ps ajx | grep mysqld 1 29678 29677 29677 ? -1 Sl 27 0:00 /usr/sbin/mysqld --daemonize --pid-file/var/run/mysqld/mysqld.pid 28738 29728 29727 28738 pts/1 29727 S 0 0:00 grep --colorauto mysqld查看mysql对应服务端口号[rootiZ5waahoxw3q2bZ ~]# netstat -nltp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1149/sshd tcp6 0 0 :::3306 :::* LISTEN 29678/mysqld登陆登陆发现登陆不上去[rootiZ5waahoxw3q2bZ ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user rootlocalhost (using password: YES)[rootiZ5waahoxw3q2bZ ~]# systemctl start mysqld # 打开mysql配置文件 [rootiZ5waahoxw3q2bZ ~]# vim /etc/my.cnf在[mysqld]最后一栏配置(不知道是什么就放在配置文件最后) 加入: skip-grant-tables 选项, 并保存退出重启mysql服务[rootiZ5waahoxw3q2bZ ~]# systemctl restart mysqld # 重启mysql服务[rootiZ5waahoxw3q2bZ ~]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.44 MySQL Community Server (GPL) Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type help; or \h for help. Type \c to clear the current input statement. mysql设置开机启动[可以不设][rootiZ5waahoxw3q2bZ ~]# systemctl enable mysqld [rootiZ5waahoxw3q2bZ ~]# systemctl daemon-reload配置my.cnf配置一下my.conf,主要是数据库客户端和服务器的编码格式port3306; character-set-serverutf8 default-storage-engineinnodb[rootiZ5waahoxw3q2bZ ~]# vim /etc/my.cnf重启[rootiZ5waahoxw3q2bZ ~]# systemctl restart mysqld[rootiZ5waahoxw3q2bZ ~]# netstat -nltp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1149/sshd tcp6 0 0 :::3306 :::* LISTEN 704/mysqld感谢你的观看启动我们下次再见