虽然navicat premium的可视化操作简便了很多的命令行操作,但作为一个coder怎么少得了命令行呢
net start mysql;—–启动
net stop mysql;—–关闭
mysql -h 主机地址 -u 用户名 -p 用户密码
exit
mysqladmin -uroot -p123 password 456;
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by ‘密码’
如,增加一个用户user1密码为password1,让其可以在本机上登录, 并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入mysql,然后键入以下命令:
grant select,insert,update,delete on . to user1@localhost Identified by “password1”;
如果希望该用户能够在任何机器上登陆mysql,则将localhost改为”%”。
如果你不想user1有密码,可以再打一个命令将密码去掉。
grant select,insert,update,delete on mydb.* to user1@localhost identified by “”;
grant all privileges on wpj1105.* to sunxiao@localhost identified by ‘123’; #all privileges 所有权限
show databases;
drop database if exists test;
create database test;
drop database test;
use test;
show tables;
drop table if exists account;
CREATE TABLE account
(
id
int(11) NOT NULL AUTO_INCREMENT,
name
varchar(20) NOT NULL,
sex
varchar(10) NOT NULL,
money
double DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
drop table account;
describe account; #可以简写为desc account;
INSERT INTO account
VALUES (‘1’, ‘aaa’, ‘1000’);
INSERT INTO account
VALUES (‘2’, ‘bbb’, ‘1000’);
INSERT INTO account
VALUES (‘3’, ‘ccc’, ‘1000’);
select * from account;
select id,name from account;
update account set name=’西瓜’ where id=4;
delete from account where id=5;
select * from account where money>20 and money<24;
select * from account where money<20 or money>24;
select * from account where money between 20 and 24;
select * from account where id in (1,3,5);
select * from account order by id asc;
select max(id),name,money from account group by sex;
select min(date) from account ;
select avg(id) as ‘求平均’ from account ;
select count(*) from account ; #统计表中总数
select count(sex) from account ; #统计表中性别总数 若有一条数据中sex为空的话,就不予以统计~
select sum(id) from account ;
select * from account limit 2,5; #显示3-5条数据
alter table test rename to test_rename;
alter table test add columnname varchar(20);
alter table tablename change columnname newcolumnname type; #修改一个表的字段名
alter table test change name uname varchar(50);
select * from test;
alter table position add(test char(10));
alter table position modify test char(20) not null;
alter table position alter test set default ‘system’;
alter table position alter test drop default;
alter table position drop column test;
alter table depart_pos drop primary key;
alter table depart_pos add primary key PK_depart_pos
(department_id,position_id);
load data local infile “D:/mysql.txt” into table MYTABLE;
source d:/mysql.sql; #或者 /. d:/mysql.sql;
转自:http://www.cnblogs.com/zhuyongzhe/p/7686105.html