默认端口: 3306
1. 安装
- ]# yum -y install mariadb-server
- ]# systemctl start mariadb
- ]# systemctl enable mariadb
2. 基本操作
- ]# MySQL #进入
- ]> show databases; # 查看所有库
- ]> create database test1 # 建库 test1
- ]> drop database test1; # 删库
- ]> exit # 退出
- ]# mysqladmin -uroot -p password "123qqq...A" #初始化修改密码
- ]# MySQL -uroot -p123qqq...A #验证登陆
- ]# VIM /etc/my.cnf # 主配置文件
- skip-networking # 跳过网络监听
3. 表格的操作 : 表字段 表记录
增 (insert) 删 (delete) 改 (update) 查 (select)
3.1 导入表到库及表操作
- ]> create database nsd;
- ]# MySQL -uroot -p123qqq...A nsd <users.sql
- ]> use nsd; #切换到 nsd 库
- ]> show tables; #显示有那些表格
- +---------------+
- | Tables_in_nsd |
- +---------------+
- | base |
- | location |
- +---------------+
- ]> select * from base; #查看 base 表所有表字段内容
3.2 where 有条件的查询
查询 nsd.base 表中 name=tom 的行记录
]> select * from base where name="tom";
查询 nsd.base 表中 passwd=123 的行记录
> select * from base where password=123;
查看 base 表结构
> desc base;
查看 MySQL.user 表中 user,host 字段所有数据
> select user,host from user;
3.3 数据库授权
]> grant select on nsd.* to [email protected] identified by '123';
3.4 复合查询
有多少人的姓名是 Barbara 同时居住在 Sunnyvale?
select * from base,location where base.name='Barbara' and location.city='Sunnyvale' and base.id=location.id;
3.5 禁止空密码访问数据库
]> select User,Host,Password from MySQL.user where Password='';
3.6 刷新表记录
]> flush privileges;
来源: http://www.bubuko.com/infodetail-3360333.html