当前位置:Gxlcms > 数据库问题 > Mariadb数据库

Mariadb数据库

时间:2021-07-01 10:21:17 帮助过:134人阅读

########################

install mariadb                           

########################

yum install mariadb-server -y ###安装mariadb

systemctl start mariadb    ###开启mariadb

mysql      ###进入数据库

mysql_secure_installation   ###安全配置向导

技术分享

技术分享


######################
数据库的基本sql语句操作
######################
1.登陆
mysql -uroot -pwestos     ###-u表示指定登陆用户,-p表示指定此用户密码

技术分享


2.查询

show databases;            ###显示数据库
use mysql;                  ###进入mysql库
show tables;                ###显示当前数据库中表
select * from user;        ###查询user表中所有内容
desc user;                ###查询user表结构
技术分享

技术分享


3.建立数据库及表格
create databases linux     ###建立名为linux的数据库
create table redhat (
username varchar(10) not null,
password varchar(10) not null
);
                          ###建立名为redhat的表格,并添加username和password
                             varchar() 定义长度 not null 不能为空
insert into redhat values (‘uaer1‘,‘passwd1‘)###向redhat表格中添加数据
delete from redhat where username=‘user1‘  ###删除redhat中user1内容
技术分享

技术分享

4.更新数据库信息
update redhat set password=‘passwd‘ where username=‘user1‘;
                          ###更改redhat表中user1的密码为passwd
update redhat set password=password(‘passwd‘) where username=‘user1‘
                          ###更改redhat表中user1的密码为passwd并加密
alter table redhat add class varchar(10);
                          ###添加新的表头
alter table redhat add class varchar(10) after username;
                         ###在username后添加class
alter table redhat drop class;
                        ###删除class项

技术分享

技术分享

5.删除数据库
drop table redhat;          ###删除redhat表
drop database redaht;       ###删除redhat数据库
技术分享

6.数据库的备份
mysqldump -uroot -p --all-databases    ###备份所有表中所有数据
mysqldump -uroot -p --all-databases > /mnt/backup.sql
                                      ###备份所以数据并保存到/mnt/backup.sql
mysqldump -uroot -p linux > /mnt/linux.sql ###备份linux库内表格到/mnt中
mysql -uroot -p < /mnt/linux.sql    ###恢复linux库内容

技术分享

技术分享

技术分享

7.用户授权
create user mmm@localhost identified by ‘mmm‘;    ###建立用户mmm密码为mmm,且只能
                                                    通过本机登陆
create user mmm@‘%‘ identified by ‘mmm‘;    ###建立mmm用户,且只能通过网络登陆
grant insert,update,delete on linux.redhat to mmm@localhost;
                                                                ###用户授权
show grants for mmm@localhost;             ###查看mmm本地用户权限
drop user mmm@localhost                    ###删除用户
技术分享

8.密码修改
mysqladmin -uroot -predhat password 123      ###修改密码
systemctl stop mariadb                   ###停止mariadb服务
mysqld_safe --skip-grant-tables &        ###跳过授权表
mysql                ###进入数据库
update mysql.user set Password=password(‘123‘) where User=‘root‘;
                                                        ###修改密码
kill -9 mysqlpid              ###关闭所有mysql的进程
systemctl start mariadb       ###开启mariadb服务

技术分享















Mariadb数据库

标签:redhat

人气教程排行