欢迎投稿

今日深度:

mariadb数据库指令,mariadb数据库

mariadb数据库指令,mariadb数据库


mariadb数据库

1.安装mysql

yum search mariadb      查找与mariadb相关的软件包
yum install mariadb mariadb-server -y  安装maridb的server软件和client软件

启动mariadb服务

systemctl start mariadb
systemctl enable mariadb

mariadb监听的端口

netstat -antlpe | grep mysql
ss -antlpe | grep mysql
vim /etc/services    所有的服务与端口默认的对应关系

只允许本地连接,阻断所有来自网络的连接

vim /etc/my.cnf
    skip-networking=1
systemctl restart mariadb

2.mariadb的初始化

设置mysql的登陆密码

 mysql_secure_installation 
 mysql -uroot -p

mysql基本操作语句

show databases;  显示数据库,类似于目录,里面包含多个表
use mysql;       进入名称为mysql的数据库中的表
show tables;     显示该数据库中的表


desc user; 显示表的结构
select * from user; 显示user表中的内容
select Host,User,Password from user; 显示表中某几列

create database cooffee;    创建以数据库名称为cooffee
create table cooffeeuser(       创建表
-> username varchar(10) not null,
-> passwd varchar(6) not null);

insert into cooffeeuser values('user1','123');     向表中插入数据
insert into cooffeeuser(passwd,username) values('456','user2');   按照指定顺序向表中插入数据
update cooffeeuser set passwd='456' where username='user1';    更新表中的内容

 alter table cooffeeuser add sex varchar(5);  添加sex列到cooffeeuser表中
 delete from cooffeeuser where username='user1';  出表中用户名为user1的记录
 drop table cooffeeuser;      除表
 drop database cooffee;       除数据库

用户和访问权限的操作

create user cooffee@localhost identified by 'hello';  创建用户cooffee,可在本机登陆,密码为hello
create user cooffee@'%' identified by 'cooffee'; 创建用户cooffee,可在远程登陆,密码为cooffee
create database mariadb;
grant all on mariadb.* to cooffee@localhost; 给cooffee@localhost用户授权,如果为all,授权所有权限   (insert,update,delete,select,create)
flush privileges;   刷新,重载受权表
show grants for cooffee@localhost;   查看用户受权
revoke delete,update on mariadb.* from cooffee@localhost; 删除指定用户授权
drop user cooffee@localhost;     删除用户


忘记mysql用户密码时,怎么找回

  • 关闭mariadb服务
    systemctl stop mariadb.service
  • 跳过受权表
    mysqld_safe –skip-grant-table &

  • 修改root密码
    mysql
    update mysql.user set Password=password(‘cooffee’) where User=’root’;

  • 关闭跳过授权表的进程,启动mariadb服务,使用新密码即可
    ps aux | grep mysql
    kill -9 pid
    mysql -uroot -p

5.mysql的备份与恢复

备份:
    mysqldump -uroot -p mariadb > mariadb.dump 
    mysqldump -uroot -pcooffee --no-data mariadb > 'date +%Y_%m_%d'_mariadb.dump 备份mariadb数据库,不备份数据库中的数据
    mysqldump -uroot -pcooffee --all-databases > mariadb4.dump  备份所有的数据库


恢复:

    mysqladmin -uroot -p create mariadb3
    mysql -uroot -p mariadb3< mar/mariadb.dump 


www.htsjk.Com true http://www.htsjk.com/mariadb/24829.html NewsArticle mariadb数据库指令,mariadb数据库 mariadb数据库 1.安装mysql yum search mariadb 查找与mariadb相关的软件包yum install mariadb mariadb-server -y 安装maridb的server软件和client软件 启动mariadb服务 systemctl sta...
相关文章
    暂无相关文章
评论暂时关闭