一、数据对象
二、DDL用法
创建数据库:create database testname
如果不存在就创建:create database if not exists testname
删除数据库:droop database testname
创建用户:create user ‘username’@‘host’ identified by ‘password’
删除用户:drop user ‘username’@‘host’
创建表:creat table tablename(先切换至testname库,use testname)
查看表:show table tablename
查看表结构:desc tablename
删除表:drop table tablename
修改表:
modify:修改字段属性,字段名字不改
change:修改字段名字
add:添加一个字段
drop:删除一个字段
alter table tablename change id ID
alter table tablename add age int(10)(默认在最后)
alter table tablename drop age
三、DML的用法
insert into tablename (name,age)values(‘sss’,28)
批量插入数据
insert into tablename(name,age)values(‘s1’,28)(‘s2’,28)
update tablename set name=‘s1’ where name=‘sss’
select语法格式,select distinct 字段 as from 表名 where group by字段 having字段 order by字段
delete from tablename where name=‘s1’
四、DCL数据控制语言
grant all previleges on test.* to ‘username‘@‘host‘ identified by ‘password‘
给username账号test库下所有表的权限
grant [select,update] on testname.tablename to ‘username‘@‘host‘ identified by ‘password‘
给username账号,testname库下tablename表的查询、更新权限
revoke [update,delete] on testname.tablename from ‘username‘@‘host‘
grant previleges on 数据库.数据表 to 用户@ 域名 identified by 密码
revoke previleges on 数据库.数据表 from 用户@域名
五、给用户添加密码
第一种办法
Mysql> SET PASSWORD FOR ‘root’@’localhost’ =PASSWORD(‘123.COM’);
给root添加密码,加密存放
改一个用户密码,或授权,密码和授权存放在内存中,所以要让mysql加
一下才生效。
FLUSH PRIVILEGES;刷新授权表,重新加载。(修改完成,都需重新加载)
第二种办法
Mysqladmin -uroot -h127.0.0.1 –p password ‘ 123.com’;
第三种办法
UPDATE user SET password=PASSWORD(‘123.COM’) WHERE USER=’root’ AND Host=[localhost,127.0.0.1];
解读:修改root密码,是locaohost,还是127.0.0.1,
UPDATE user SET password=PASSWORD(‘123.COM’) WHERE USER=‘root’;
解读:不管是localhost还是127.0.0.1,只要是root用户的,密码全部被修改。
给远程用户添加密码权限
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’192.168.%.%’ IDENTIFIED BY ‘passwprd’
允许192.168网段的所有主机,通过root用户,连接任意表,任意库,密码password
FLUSH PRIVILEGES;
远程登陆:mysql -uroot -p -h192.168.1.1
原文:https://www.cnblogs.com/xysun/p/12167775.html