如何使用mysql? 其余语法与sql语法完全相同,每条语句以分号结尾
1、查询数据库结构
show database; 显示数据库列表
show tables;
describe user; 显示数据表的结构
select database(); 显示当前正在使用的数据库名
select user(); 显示当前登录的用户
drop database if exists student;
id int not null; 设置字段结构
primary key(id); 设置字段属性
注:可以将sql语句写成脚本然后导入 mysql -u root -p < studrnt.sql
注意:数据库文件默认存放在/usr/local/mysql/var/目录下
2、数据库权限设置(安全性)
授予权限
grant 权限列表 on 数据库.表名 to 用户名@来源地址 identitied by ‘密码’
Ex:grant select on *.* to test@192.168.1.1 identified by ‘123’;
查看权限:
show grants for 用户名@来源地址
Ex:show grants for test@localhost;
撤销权限:
语法:revoke 权限列表 on 数据库.表名 from 用户名@来源地址
Ex: revoke select on *.* from test@192.168.1.1
3、数据库的备份和恢复
备份:
mysql -u root -p 数据库名 表名 > 导出的文件名
mysql -u root -p --databases 数据库名 > 导出的文件名
mysql -u root -p --opt --all-databases > .....
恢复:
语法: mysql -u root -p 数据库名 表名 < 导入的备份文件名
Ex: mysql -u root -p student < ..... 恢复表
mysql -u root -p < ... 恢复整个数据库,无需指定库名
转载于:https://blog.51cto.com/sysmanager/1287546