当前位置:网站首页>Linux 安装Mysql
Linux 安装Mysql
2022-08-06 04:01:00 【Felix-Xu】
下载mysql文件
下载mysql文件5.7.32包,我已经上传到文件中。也可以点击下载 如下图所示:

删除Linux下默认安装的MariaDB
# 查找mariadb安装包名字
rpm -qa | grep -i mariadb
# 输出为空,代表没有mariadb
# 卸载mariadb安装包,mariadb-xxx 是上一条命令查出的结果
rpm -e --nodeps mariadb-xxx上传文件并解压
创建要上传的目录,这里我的目录为
cd /usr/local/package
mkdir mysql将mysql安装包上传至目录/usr/local/package/mysql/下,然后解压
tar -xvf mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar安装
rpm -ivh mysql-community-common-5.7.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.32-1.el7.x86_64.rpm注:https://centos.pkgs.org/下载依赖https://centos.pkgs.org/
至此,mysql数据库就安装完成了
启动mysqld服务
执行以下命令
# 启动服务 命令后有空格会报错
systemctl start mysqld
# 查看服务状态
systemctl status mysqld
扩展:
# 停止服务
systemctl stop mysqld
# 重启服务
systemctl restart mysqld修改mysql的登录密码
1、设置跳过登录密码
vi /etc/my.cnf在最后一行添加代码
# 跳过密码登录
skip-grant-tables
保存后,然后重启服务
systemctl restart mysqld2、修改密码
登录mysql,刚才已经设置了跳过密码登录,所以我们只要输入登录命令,回车两次就可以了
mysql -u root -p修改密码
#使用mysql数据库
use mysql;
#修改密码
update user set authentication_string=password('新密码') where user = 'root';
update user set password_expired='N' where user = 'root';
#退出
quit;然后重启服务
此时把刚才配置的跳过密码配置代码去掉或者注释掉就可以了。
# 重启服务
systemctl restart mysqld
# 修改my.cnf
vi /etc/my.cnf
然后再次重启mysqld服务
systemctl restart mysqld然后输入命令
mysql -u root -p
输入刚才设置的密码:新密码,出现mysql交互则说明刚才设置成功。
设置MySQL远程连接
新安装MySQL不设置远程连接,无法在其他设备的MySQL客户端进行连接。
# 访问mysql库
use mysql;
# 使root能再任何host访问
update user set host = '%' where user = 'root';
# 刷新
FLUSH PRIVILEGES;
# 退出
\q防火墙开启需要把3306加入白名单
服务器防火墙开启的情况下,必须要让防火墙开启myslq的3306端口,其他服务器上的应用才能成功连接。
systemctl status firewalld #查看防火墙状态
firewall-cmd --permanent --zone=public --add-port=3306/tcp #防火墙开启端口
firewall-cmd --reload #重启防火墙
firewall-cmd --query-port=3306/tcp #检查端口是否开启或者直接关闭服务器的防火墙。
systemctl status firewalld #查看防火墙状态
systemctl stop firewalld #临时关闭
systemctl disable firewalld #永久关闭,即设置开机的时候不自动启动设置编码格式
修改配置文件
vi /etc/my.cnf
# 在[mysqld]下添加
collation_server=utf8_general_ci
character_set_server=utf8
default-storage-engine=INNODB
# 在[client]下添加(如果没有[client],则创建[client])
[client]
default_character-set=utf8
重启服务
systemctl restart mysqld登录mysql
mysql -u root -p查看mysql编码
show variables like 'character_set_%';
此时可以查看修改mysql编码已经为UTF-8了
边栏推荐
- ctf (finalrec)
- xctf attack and defense world web master advanced area command_execution
- 2022年天猫七夕价格便宜吗?天猫七夕节有什么优惠?
- 字节跳动 Flink 状态查询实践与优化
- 【翻译】无服务器架构:利与弊
- Datax及Datax-web 下载使用
- chrome NET::ERR_CERT_INVALID 使用thisisunsafe 解决浏览器发生了什么
- What is an Egg. The js, it have what features, installation of an Egg framework, definition of routing, what's Controller is the Controller, CORS configuration, the json configuration, a get request,
- 电赛电源类题型之问
- 2.cuBLAS开发指南中文版--使用cuBLAS API
猜你喜欢
随机推荐
HTAP 能够取代 OLAP 吗?
go mod why
Flink-cdc 同步mysql数据
牛客题目——买卖股票的最好时机(一)、(二)、(三)、设计LRU缓存结构
Internet protocol overview
Preprocessing (in-depth understanding of C language)
移除超出规定List最大数量的数据
Wang Qi, Secretary of the Party Committee and President of Shanghai Pudong Development Bank Changsha Branch, and Jiang Junwen, President of Huarong Xiangjiang Bank, visited Kylin Principal for investi
Google Cloud Security Summit
【无标题】
Mysql安装 求大拿解答
14. go channel
【图像分类】2021-Twins NeurIPS
Example of host command requesting DNS lookup
firewall and ufw notes
89.(cesium之家)cesium聚合图(自定义图片)
2018HBCPC Partial Solutions
NetCore - custom exception handling
4.cuBLAS开发指南中文版--CUDA 数据类型引用
gst-launch-1.0
![洛谷 : P1020 [NOIP1999 普及组] 导弹拦截](/img/c1/0459b49d38ad8979c81509867e2d10.png)



![LeetCode: 623. Add a line to the binary tree [DFS or BFS]](/img/83/1512977843d431f4fa9760c913b5fc.png)



