create user ben identified by ‘P@$$w0rd’;
select user,host from mysql.user;
set password for ben = password(‘Password123!’);
增加用户 test1 密码 abc,让它可以在任何主机上登录,并对所有数据库有查询,插入,修改,删除的权限
格式: grant select on 数据库.表 to 用户名@登录主机 identified by “密码”。 ”%”代表所有主机
*特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了 ,而是将加密后的用户密码存储于authentication_string字段
将数据库test导出到mysql.test文件,后面是一个文本文件 mysqldump –opt test > mysql.test
mysqldump -u root -p123456 –databases dbname > mysql.dbname
mysqlimport -u root -p123456 < mysql.dbname
将文本数据导入数据库,文本数据的字段之间用tab键隔开 use test load data local infile “文件名” into table 表名; load data local infile “D:/mysql.txt” into table mytable;
导入.sql 文件命令 mysql> use database; mysql> source /root/mysql.sql;
删除表,而不是其内容,没有确认,也不能撤销 drop table 表名;
清空表记录 ,即删除所有行,不建议使用DELETE,可使用truncate TABLE语句,它完成相同的工作,但速度更快(TRUNCATE实际是删除原来的表并重新创建一个表,而不是逐行删除表中的数据)
插入表记录 insert into 表名 values(, ,);
alter table vendors add vend_phone char(20);
alter table vendors drop column vend_phone;
show create table productnotes;
rename table customers2 to customers;
rename table backup_customers to customers, -> backup_vendors to vendors, -> vackup_products to products;
alter table tablename ( add column datatype [null|not null] [constraints], change column columns datatype [null|not null] [constraints], drop column, );
create index indexname on tablename (column [asc|desc], …);
alter table user modify column im varchar(4000);
select distinct creator from contacts;
select id from contacts limit 5;
select id from contacts limit 5, 5;
select id from contacts limit 1;