mysql数据类型之数值
mysql数据库之属性设置
mysql数据类型之日期
mysql数据类型之字符串
1. 安装mysql
yum search mariadb
//查找与mariadb有关的软件包
yum install mariadb mariadb-server -y
//安装mariadb的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 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”);
//按照指定顺序向表中插入数据
update westosuser set passwd=‘456’ where username=“user1”;
//更新表中的内容
alter table westosuser add sex varchar(3);
//添加sex列到westosuser表中
delete from westosuser where username=“user1”;
//删除表中用户名为user1的记录 //添
drop table westosuser;
//删除表
drop database westos;
//删除数据库
用户和访问权限的操作
create user hello@localhost identified by ‘hello’;
//创建用户hello,可在本机登陆,密码为hello
create user hello@’%’ identified by ‘hello’;
//创建用户hello,可在远程登陆,密码为hello
create database mariadb;
//创建一数据库mariadb,对普通用户进行
grant all on mariadb.* to hello@localhost;
//给hello@localhost用户授权,如果为all,授权所有权限
(insert,update,delete,select,create)
flush privileges;//刷新,重载授权表
show grants for hello@localhost;//查看用户授权
revoke delete,update on mariadb.* from hello@localhost;
//删除指定用户授权
drop user hello@localhost;//删除用户
4. 忘记mysql用户密码时,怎么找回?
1. 关闭mariadb服务
systemctl stop 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 mysql
kill -9 pid
mysql -uroot -p
5. mysql的备份与恢复
备份:
mysqldump -uroot -p mariadb >mariadb.dump
mysqldump -uroot -pwestos --no-data mariadb > date +%Y_%m_% d
_mariadb.dump
mysqldump -uroot -pwestos --all-databases >mariadb4.dump
恢复:
mysqladmin -uroot -pwestos create mariadb2
mysql -uroot -pwestos mariadb2< mariadb.dump
6. 通过网页管理数据库