1.连接MySQL
mysql -u root -p
2.修改MySQL配置文件
sudo gedit /etc/my.cnf
3.常用指令
show databases;——显示当前数据库
drop database test——删除数据库test
create database test——创建数据库
use test;——连接的数据库
create table student(id int, name varchar(20));——创建数据库
show tables;——展示数据库
insert into student (id,name) values(1,'fanfei');——插入记录
select * from student;——查询记录
4.用户操作
新建用户:grant 权限 on 数据库.* to 用户名 @登录主机 identified by "密码"; flush privileges;
权限:all privileges或select,insert,update,delete; 数据库,表:数据库名.*(制定库) 或 *.*(全部库)
@登陆主机:@"%"指任意主机,@"localhost"指本地; 用户名,密码
>grant select,insert,update,delete on *.* to hive @"%" identified by "ff";
>grant all privileges on cab.* to test1 @"localhost" identified by "3401";
>flush privileges
重新登陆:
>exit;
>/usr/local/mysql/mysql/bin/mysql -u hive -p;
修改密码:update mysql.user set password=password('newpwd') where user='hive' and host='localhost';
>update mysql.user set password=password('123456') where User='test1' and Host='localhost'; >flush privileges;
删除用户 mysql>delete from user where user='test2' and host='localhost'; mysql>flush privileges; 删除账户及权限 drop user 用户名@'%' drop user 用户名@localhost