当前位置:网站首页>mariadb学习笔记
mariadb学习笔记
2022-06-26 12:40:00 【浪里划船】
安装mariadb
如果没有指定mariadb的yum源,直接安装也能安装成功,但是版本是5.5的应该是阿里云默认安装版本,建议大家尽量安装新的版本。
# 编辑yum源文件
vim /etc/yum.repos.d/epel.repo
# 添加mariadb的yum镜像源
[mariadb]
name = MariaDB
baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.3/centos7-amd64/
gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
# 安装mariadb
sudo yum -y install mariadb mariadb-server
# 启动数据库
sudo systemctl start mariadb
# 重启数据库
sudo systemctl restart mariadb
# 设置开机启动
sudo systemctl enable mariadb mariadb
# 查看数据库状态
sudo systemctl status mariadb
# 卸载mariaddb
yum remove mariadb
rm -f /etc/my.cnf
rm -rf /var/lib/mysql/
rpm -qa|grep mariadb
运行mariadb安全配置命令
通过执行mysql_secure_installation进行安全配置,根据实际情况用Y/N回复以下问题:设置root密码、删除匿名用户、禁用 root 远程登录、删除测试数据库,重新加载权限表(见下图)。
完成上面的安全配置,重新执行以下命令
# 重启数据库
sudo systemctl restart mariadb
# 查看数据库状态
sudo systemctl status mariadb
结果显示如下图
从上面的启动信息可以看到mariadb已经成功启动了,并且版本是符合镜像源的信息10.3版本
操作用户
# 登陆数据库
mysql -uroot -p123456
# 指定数据库
use mysql;
# 查询用户
select user,password,host from user;
# 创建用户任意ip访问
create user 'zhangsan'@'%' identified by '123456';
# 创建用户指定ip访问
create user 'lisi'@'102.12.56.3' identified by '123456';
# 重命名用户
rename user 'zhangsan'@'%' to 'zhangsan1'@'%';
# 删除用户
drop user 'yangxin'@'localhost';
管理权限
# 授予用户zhangsan的blog数据库所有权限
grant all privileges on blog.* to 'zhangsan'@'%' identified by '123456';
# 授予用户zhangsan的blog数据库操作数据增删改查权限
grant select,insert,update,delete on blog.* to 'zhangsan'@'%' identified by '123456';
# 授予用户zhangsan的所以数据库操作权限
grant all privileges on *.* to 'zhangsan'@'%' identified by '123456' with grant option;
# 回收权限
revoke create on *.* from '[email protected]%';
# 刷新权限
flush privileges;
修改root密码
方法一
# 直接在shell命令行使用 mysqladm 命令修改**需要用root在终端登陆**
mysqladmin -uroot -p password newpassword
会提示输入旧密码,如果之前没有设置,直接回车就行了。
方法二
# 登陆数据库修改密码之update
use mysql;
update user set password = password('123456') where user ='root';
SET password for'root'@'localhost'=password('123456');
# 切记一定要刷新权限
flush privileges;
忘记密码如何修改
# 关闭mariadb服务
sudo systemctl stop mariadb
# 跳过授权的方式来启动 mariadb
mysqld_safe --skip-grant-tables & ps -ef | grep 8690
操作结果如下图
当跳过授权启动时,可以不需要密码直接msyql登陆数据库。这个时候可以通过上面的方式修改密码即可;当密码修改后,即使出于跳过授权状态下使用空密码也不能登陆了;杀死该跳过授权进程kill -9 8690,启动mariadbsudo systemctl start mariadb
边栏推荐
猜你喜欢

轻流完成与「DaoCloud Enterprise 云原生应用云平台」兼容性认证

Stream流学习记录

Xiaobai lazy special-win10-win11 one click installation version
![Vivado 错误代码 [DRC PDCN-2721] 解决](/img/de/ce1a72f072254ae227fdcb307641a2.png)
Vivado 错误代码 [DRC PDCN-2721] 解决

OPLG: 新一代云原生可观测最佳实践

文件远程同步、备份神器rsync
![[esp32-c3][rt-thread] run RT-Thread BSP minimum system based on esp32c3](/img/4a/503240b332e3279047c438f1d9845e.png)
[esp32-c3][rt-thread] run RT-Thread BSP minimum system based on esp32c3

Less than 40 lines of code to create a blocprovider

记一次phpcms9.6.3漏洞利用getshell到内网域控

Processsing 鼠标交互 学习
随机推荐
无人机遥感在森林监测的部分应用研究案例总结
倍福PLC通过程序获取系统时间、本地时间、当前时区以及系统时间时区转换
Summary of some application research cases of UAV Remote Sensing in forest monitoring
Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control
Basic principle and application routine of Beifu PLC rotary cutting
Redis learning - 03 transaction
Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology
National standard gb28181 protocol easygbs video platform TCP active mode streaming exception repair
Echart堆叠柱状图:色块之间添加白色间距效果设置
find及du -sh显示权限不够的解决方法
倍福PLC旋切基本原理和应用例程
LeetCode_栈_中等_150. 逆波兰表达式求值
National standard gb28181 protocol easygbs cascaded universal vision platform, how to deal with live message 403?
软件测试测试常见分类有哪些?
别乱用 FULL_CASE 和 PARALLEL_CASE
Copy multiple Excel files and name them different
Deep parsing MySQL binlog
C - Common Subsequence
C语言:练习题二
opencv高速下载