Mysql基础操作
设置密码
mysqladmin -uroot password "123456“(没有密码的情况)
mysqladmin -uroot password "456789" -p123456(知道原密码)
update mysql.user set password=password("123456") where user="root" and host="localhost";
(不知道密码时)/my.cnf skip-grant-tables
flush privileges;(刷新权限表)
set password from 'root'@'localhost'=password('123456');(不用刷新权限表)
数据库授权
grant all on *.* to mas@localhost identified by "123456" with grant option;
(给mas用户授予root权限)
grant write on database.* to user@host identified by "pass";
(user在host主机对database库有写权限)
grant select,insert,update,delete on *.* to user@"%" identified by "123456";
(user用户在任何主机上对所有数据库有这些权限)
grant select,insert,update,delete on mydatabase.* to myuser@localhonst identified by "123456";(myuser用户通过密码123456,对mydatabase库进行该权限操作)
增加一个用户custom,他能从主机localhost,server,domain和whitehouse.gov连接。
它只从localhost存取bankacount数据库,从whitehost.gov存取expenses数据库和从所有3台主机存取customer数据库。
它想要从所有3台主机上使用口令stuipid.
shell> mysql --user=root mysql
grant select,insert,update,delete,creat,drop on bankaccount.* to custom@localhost identified by 'stuipid;
grant select,insert,updete,delete,creat,drop on custom@'%' identified by 'stupid';
创建库
create database mas;(不指定字符集)
drop database mas(删除库)
创建表
create table mas (id int);(使用默认引擎)
create table mas (id int) engine=memory; (指定引擎)
drop table mas;(删除表)
show databases;(查看有哪些库)
use 库名;(进入该库)
select databases();(查看进入了那个库(pwd))
show tables; (查看当前库有哪些表)
select user();(查看当前登录用户)
select * from mas;(查看表内容)
desc 表名;(描述表结构)
rename table mas1 to mas2; (重命名表名)
show variables like "character%"(查看数据库字符集)
insert into aaa.emp(emp_id,ename) values (1,‘aaa');
insert into aaa.emp(emp_id,ename) values (2,‘bbb');
insert into aaa.emp(emp_id,ename) values (3,‘ccc');
晓桂科技
领取专属 10元无门槛券
私享最新 技术干货