mariadb数据库及其应用
1.执行以下命令
在超级用户下操作
yum search mariadb
yum install mariadb-server.x86_64
2.启动服务
systemctl start mariadb
systemctl status mariadb 显示状态
如果是这样,代表运行正常
3.设置信息
netstat-antple | grep mysql
mysql
执行完退出就好了
mysql_secure _installation
出现此图时,回车就行
这之后会提示是否删除匿名用户,是否允许远程登陆等,根据自己情况而定
但是这里会以超级用户身份进入 同时设置超级用户密码
如图
登陆时,执行命令
mysql -uroot -predhat 此处我设置root用户的密码是redhat
如果删除了匿名用户,那么默认的匿名用户登陆不了
登陆成功会如图显示
4.mysql基本操作语句
show databases 显示数据库
use mysql 进入名称为mysql的数据库
show tables 显示该数据库中的表
desc user 显示表的结构
select * from user 显示user表中的内容
select Host ,User,Password from user 显示表中某几列
create database westos 创建数据库名称为westos
create table westosuser(username varchar(10) not null, passwd varchar(6) not null
注意:每一个命令结束后都要用分号结尾,意为命令结束。
insert into westosuser values('user1' , '123') 向表中插入内容
insert into westosuser(passwd,username) values ('456','user2') 按照指定顺序向表中插入数据
最后显示表中的数据
alter table westosuser add sex varchar(3)
添加sex列到westosuser表中
delete from westosuser where username='user1'
删除表中用户名为user1的记录
drop table westosuser
删除westosuser表
drop database westos
删除数据库
5.访问权限
create user [email protected] identified by 'hello'
创建用户hello,可在本机登陆,密码为hello
create user [email protected]'%' identified by 'hello'
创建用户hello,可在远程登陆,密码为hello
grant all on mariadb.* to [email protected]
给[email protected]用户授权,拥有对mariadb数据库的操作权限
show grants for [email protected]
查看用户授权
revoke delete,update on mai=riadb.* from [email protected]
删除指定用户授权
drop user [email protected]
删除用户
6.忘记mysql用户密码时,如何找回
1.关闭mariadb服务
systemctl stop update mariadb
2.跳过授权表
mysqld_safe --skip-grant-table &
3.修改root密码
mysql
>update mysql.user set Password=password('westos') where User='root'
4.关闭跳过授权表的进程,启动mariadb服务,使用新密码即可
ps aux | grep mysqlmar
kill -9 pid
mysql -uroot -p
7.mysql的备份与恢复
备份:
mysqldump -uroot -p mariadb > mariadb.dump
mysqldump -uroot -pwestos --no-data mariadb > 'data'_ mariadb.dump
mysqldump -uroot -pwestos --all-databases > mariadb4.dump
恢复:
mysqladmin -uroot -pwestos create mariadb2
mysql -uroot -pwestos mariadb2 < mariadb.dump
重点注意对象:当创建的数据库和表内需要中文时,按以下命令创建
create database employee default charset utf8
8.趣味小练习
要求:
命令如下
查询信息: select * from emplyee