当前位置:网站首页>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的目录)
边栏推荐
- 数据库高级学习笔记--SQL语句
- AcWing 1298.曹冲养猪 题解
- L2-004 这是二叉搜索树吗? (25 分)
- Tcp/ip protocol (UDP)
- Project practice - background employee information management (add, delete, modify, check, login and exit)
- 分布式節點免密登錄
- [Flink] Flink learning
- Valentine's Day flirting with girls to force a small way, one can learn
- Composition des mots (sous - total)
- 搞笑漫画:程序员的逻辑
猜你喜欢
分布式节点免密登录
{one week summary} take you into the ocean of JS knowledge
02 staff information management after the actual project
【CDH】CDH5.16 配置 yarn 任务集中分配设置不生效问题
人脸识别 face_recognition
One click extraction of tables in PDF
【flink】flink学习
快来走进JVM吧
double转int精度丢失问题
UDS learning notes on fault codes (0x19 and 0x14 services)
随机推荐
Rhcsa certification exam exercise (configured on the first host)
[Bluebridge cup 2020 preliminary] horizontal segmentation
4. Install and deploy spark (spark on Yan mode)
MATLAB学习和实战 随手记
What does BSP mean
Heating data in data lake?
{一周总结}带你走进js知识的海洋
MySQL and C language connection (vs2019 version)
SQL时间注入
[yarn] yarn container log cleaning
4、安装部署Spark(Spark on Yarn模式)
Connexion sans mot de passe du noeud distribué
2019腾讯暑期实习生正式笔试
Learn winpwn (3) -- sEH from scratch
【yarn】CDP集群 Yarn配置capacity调度器批量分配
About string immutability
Learning question 1:127.0.0.1 refused our visit
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_ s instead
Common regular expression collation
【kerberos】深入理解kerberos票据生命周期