当前位置:网站首页>Linux yum安装MySQL
Linux yum安装MySQL
2022-07-06 09:16:00 【@小蜗牛】
注意:只需要在master节点安装mysql
先装mysql源,再装mysql
目录
2.1切换root用户(密码:zkpk)
[[email protected] ~]# su root
2.2查看并卸载系统自带的mariadb-lib数据库
[[email protected] zkpk]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[[email protected] zkpk]# yum -y remove mariadb-libs-*
2.3添加MySQL yum源
注意:此步骤需要联网操作
2.3.1下载mysql源安装包
[[email protected] zkpk]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2.3.2安装mysql源
[[email protected] zkpk]# yum -y localinstall mysql57-community-release-el7-8.noarch.rpm
2.3.3检查mysql源是否安装成功
[[email protected] zkpk]# yum repolist enabled | grep "mysql.*-community.*"
2.4安装MySQL
注意:安装mysql服务端时,客户端会作为依赖自动安装
[[email protected] zkpk]# yum -y install mysql-community-server
2.5启动MySQL服务
2.5.1命令
[[email protected] zkpk]# systemctl start mysqld
2.5.2查看MySQL的启动状态(出现图中绿色running字样表示成功)
[[email protected] zkpk]# systemctl status mysqld
2.6设置开机启动
[[email protected] zkpk]# systemctl enable mysqld
#重新载入 systemd,扫描新的或有变动的单元
[[email protected] zkpk]# systemctl daemon-reload
2.7修改root默认密码
2.7.1查看mysql安装生成的随机默认密码(/var/log/mysqld.log文件中)
[[email protected] zkpk]# grep 'temporary password' /var/log/mysqld.log
2.7.2登录mysql(密码为上图红框标注部分)
[[email protected] zkpk]# mysql -uroot -p
2.7.3修改mysql密码为“MyNewPass4!”(建议第一种)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者:
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR
1819 (HY000): Your password does not satisfy the current policy
requirements错误,如下图所示:
2.8修改mysql密码策略
2.8.1查看msyql密码策略的相关信息;退出mysql命令行
mysql> show variables like '%password%';
mysql> exit;
2.8.2关闭密码策略
2.8.2.1禁用mysql密码策略,向my.cnf文件末尾添加如下配置(/etc/my.cnf),保存、退出
[[email protected] zkpk]# vim /etc/my.cnf
validate_password = off
2.8.2.2重新启动mysql服务使配置生效:
[[email protected] zkpk]# systemctl restart mysqld
2.9修改root密码为zkpk
2.9.1登录mysql(密码:MyNewPass4!)
[[email protected] zkpk]# mysql -uroot -p
2.9.2修改mysql的root用户密码为zkpk(建议第一种)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'zkpk';
或者
mysql> set password for 'root'@'localhost'=password('zkpk');
2.10添加zkpk用户并赋予远程登录权限,然后退出mysql命令行
mysql>grant all on *.* to [email protected]'%' identified by 'zkpk';
mysql>grant all on *.* to [email protected]'localhost' identified by 'zkpk';
mysql>grant all on *.* to [email protected]'master' identified by 'zkpk';
mysql>flush privileges;
mysql>exit;
2.11配置默认编码为utf8
2.11.1修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,即下图红框部分;保存、退出
[[email protected] zkpk]# vim /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
2.11.2重新启动mysql服务
[[email protected] zkpk]# systemctl restart mysqld
2.11.3查看数据库默认编码
2.11.3.1登录mysql(密码:zkpk)
[[email protected] zkpk]# mysql -uroot -p
2.11.3.2查看编码;然后退出mysql命令行
mysql> show variables like '%character%';
mysql> exit;
2.12查看防火墙是否关闭
2.12.1执行命令;若出现下红框dead字样,说明防火墙关闭
[[email protected] zkpk]# systemctl status firewalld
2.12.1若防火墙没有关闭,执行以下步骤。远程访问开放防火墙mysql的3306端口
[[email protected] zkpk]# firewall-cmd --add-port=3306/tcp
2.13MySQL的几个重要目录
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
数据库目录 /var/lib/mysql/
配置文件 /usr/share/mysql(mysql.server命令及配置文件)
相关命令 /usr/bin(mysqladmin mysqldump等命令)
启动脚本 /etc/rc.d/init.d/(启动脚本文件mysql的目录)
边栏推荐
- Machine learning notes week02 convolutional neural network
- Solution of deleting path variable by mistake
- Niuke novice monthly race 40
- Face recognition_ recognition
- 【yarn】Yarn container 日志清理
- Codeforces Round #771 (Div. 2)
- PHP - whether the setting error displays -php xxx When PHP executes, there is no code exception prompt
- Mysql的索引实现之B树和B+树
- How to build a new project for keil5mdk (with super detailed drawings)
- 01 project demand analysis (ordering system)
猜你喜欢
vs2019 桌面程序快速入门
MySQL与c语言连接(vs2019版)
About string immutability
In the era of DFI dividends, can TGP become a new benchmark for future DFI?
Vs2019 desktop app quick start
解决安装Failed building wheel for pillow
Machine learning notes week02 convolutional neural network
[CDH] cdh5.16 configuring the setting of yarn task centralized allocation does not take effect
Knowledge Q & A based on Apache Jena
AcWing 1298.曹冲养猪 题解
随机推荐
Pytoch Foundation
【yarn】CDP集群 Yarn配置capacity调度器批量分配
AcWing 179.阶乘分解 题解
wangeditor富文本组件-复制可用
Kept VRRP script, preemptive delay, VIP unicast details
[Kerberos] deeply understand the Kerberos ticket life cycle
误删Path变量解决
encoderMapReduce 随手记
02 staff information management after the actual project
Base de données Advanced Learning Notes - - SQL statements
MTCNN人脸检测
SQL时间注入
Library function -- (continuous update)
Solution of deleting path variable by mistake
L2-004 这是二叉搜索树吗? (25 分)
[Bluebridge cup 2021 preliminary] weight weighing
L2-001 emergency rescue (25 points)
nodejs 详解
Integration test practice (1) theoretical basis
[NPUCTF2020]ReadlezPHP