mysql -h {host} -u {username} -P {port} -p -t {dbname}
create user zhangsan identified by 'zhangsan';
create user misp identified by 'misp';
grant {privilegesCode 授权类型} on zhangsanDb.* to zhangsan@'%';
flush privileges;
privilegesCode授权类型枚举:
* all privileges:所有权限。
* select:读取权限。
* delete:删除权限。
* update:更新权限。
* create:创建权限。
* drop:删除数据库、数据表权限。
update mysql.user set password = password('zhangsannew') where user = 'zhangsan' and host = '%';
flush privileges;
drop user zhangsan@'%';
alter table <table_name> modify <field_name> <field_type>;
alter table <table_name> modify id int auto_increment;
alter table <table_name> AUTO_INCREMENT=10000;
alter table <table_name> rename to <new_table_name>
# 添加--no-data参数可只导出表结构
mysqldump -h {host} -u {username} -P {port} -p {password} -t {dbname} --tables {tb1} {tb2} ... > dump.sql # 不指定--tables参数则导出所有表
mysql -h {host} -u {username} -P {port} -p {password} -t {dbname} < dump.sql
1. 复制表结构及数据到新表:
create table <new table> as select * from <old table>
或:
create table <new table> like <old table>;
insert into <new table> select * from <old table>;
2. 只复制表结构到新表(此时会默认使用innodb)
create table <new table> as select * from <old table> where 1 = 2
SELECT
TABLE_NAME AS 'Table',
ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2) AS 'Size in MB'
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = "xxx";
mysqldump -h {host} -u {username} -P {port} -p {password} -t {dbname} --tables {tb1} {tb2} ... -T {$filepath} mydb customers --fields-terminated-by=',' --fields-enclosed-by='\"'
mysql -h 127.0.0.1 -u root -p XXXX -P 3306 -e "select * from table" > /tmp/test/txt
联合唯一索引的字段中,当出现null值时,唯一性约束不会生效。