MySQL数据库学习笔记
常用:
etstartmysql启动数据库,
etstopmysql停止数据库数据库具体保存在mysql的data目录下
具体操作
一,连接MySQL格式:mysqlh远程主机地址u用户名p回车输入密码进入:
mysqlurootp回车E
terpassword输入密码就可以进入mysql进入了退出命令exit或者ctrlD
二,MySQL管理与授权1修改密码:格式:mysqladmi
u用户名p旧密码password新密码
2增加新用户gra
tcreateselectupdate授予相关的操作权限o
数据库to用户名登录主机ide
tifiedby密码
f操作实例:
给root用户添加密码mysqladmi
urootpassword52
etseek因为开始root没有密码所以p旧密码一项可以省略登陆测试:mysqlurootp回车输入密码成功登陆
将原有的mysql管理登陆密码52
etseek改为52chi
amysqladmi
urootp52
etseekpassword52chi
a
创建数据库添加用户并授予相应的权限mysqlcreatedatabasephpbbQueryOK1rowaffected002sec
mysqlusephpbbDatabasecha
gedmysqlgra
tcreateselectupdatei
sertdeletealtero
phpbbtophpbbrootlocalhostide
tifiedby52
etseekQueryOK0rowsaffected000sec
f授予所有的权限gra
tallprivilegeso
bbstobbsrootlocalhostide
tifiedby52
etseek
回收权限:revokecreateselectupdatei
sertdeletealtero
phpbbfromphpbbrootlocalhostide
tifiedby52
etseek
完全将phpbbroot这个用户删除usemysqldeletefromuserwhereuserphpbbroota
dhostlocalhostflushprivileges刷新数据库
三,数据库简单操作1显示数据库列表showdatabasesmysqltest2使其成为当前操作数据库usemysql打开数据库showtables显示mysql数据库中的数据表3显示数据表的表结构
fdescribe表名describeuser显示user表的表结构:4创建数据库建表createdatabase数据库名use数据库名;createtable表名字段设定列表5删除数据库,册除表dropdatabase数据库名droptable表名6显示表中的记录selectfrom表名7修改数据库结构增加字段:altertabledb
ameaddcolum
字段名字段选项修改字段:altertabledb
amecha
ge旧字段名新字段名选项删除字段altertabledb
amedropcolum
字段名
实例操作:createdatabaseofficeuseofficemysqlcreatetableperso
almember_
ochar5
ot
ull
amechar
fbirthdaydateexam_scoreti
yi
tprimarykeymember_
oQueryOK0rowsaffected001secdescperso
al显示表结构:FieldTypeNullKeyDefaultExtramember_
ochar5PRI
amecharYESNULLbirthdaydater