MySQL修改表

MySQL修改表_第1张图片

1.1
create database Market;
1.2
mysql> create table customers (
    -> c_num int(11) primary key not null auto_increment,
    -> c_name varchar(50),
    -> c_contact varchar(50),
    -> c_city varchar(50),
    -> c_birth datetime not null
    -> );
1.3
mysql> alter table customers drop c_contact;
mysql> alter table customers add c_contact varchar(50) after c_birth;
1.4
alter table customers modify c_name varchar(70);
1.5
alter table customers change c_contact c_phone varchar(50);
1.6
alter table customers add c_gender char(1);
1.7
rename table customers to customers_info;
1.8
mysql> alter table customers_info drop c_city;
1.9
mysql> show engines;//查看支持的存储引擎
show variables like '%storage_engine%'; //查看默认的存储引擎
ALTER table customers_info engine=MyISAM;
结果:
mysql> desc customers_info;
+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| c_num    | int(11)     | NO   | PRI | NULL    | auto_increment |
| c_name   | varchar(70) | YES  |     | NULL  |                |
| c_birth  | datetime    | NO   |     | NULL    |                |
| c_phone  | varchar(50) | YES  |     | NULL    |                |
| c_gender | char(1)     | YES  |     | NULL    |                |
+----------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

MySQL修改表_第2张图片

mysql> create table orders (
    -> o_num int(11) primary key not null auto_increment unique,
    -> o_date date,
    -> o_id int(11),
    ->foreign key(o_id) references customers_info(c_num)
    -> );
//注意,在上题中更改了引擎,添加外键不成功的原因可能是引擎的原因
2.2
show create table orders;//先查看外键名
 alter table orders drop foreign key orders_ibfk_1;//再删除外键
mysql> drop table customers_info;//再删除表customers_info

MySQL修改表_第3张图片

3.1
grant select,insert on team.player to account1@'localhost' identified by 'Oldpwd111.';
grant update(info) on team.player to account1@'localhost' identifieed by 'Oldpwd111.';
3,2
mysql> SET GLOBAL validate_password_policy='LOW';
Query OK, 0 rows affected (0.00 sec)

mysql> SET GLOBAL validate_password_length=0;
Query OK, 0 rows affected (0.00 sec)

mysql>  SET GLOBAL validate_password_special_char_count=0;
Query OK, 0 rows affected (0.00 sec)

mysql> SET GLOBAL validate_password_mixed_case_count=0;
Query OK, 0 rows affected (0.00 sec)

mysql> SET GLOBAL validate_password_number_count=0;
Query OK, 0 rows affected (0.00 sec)

mysql>  SET GLOBAL validate_password_length=0;
Query OK, 0 rows affected (0.00 sec)

mysql> alter user account1@'localhost' identified by 'newpwd2';
Query OK, 0 rows affected (0.00 sec)
//修改权限限制后用户account1可以设置简单密码
3.3
mysql> flush privileges;
//刷新权限表
3.4
 SHOW GRANTS FOR 'account1'@'localhost';//查看权限

GRANT USAGE ON *.* TO 'account1'@'localhost'                                     |
| GRANT SELECT, INSERT, UPDATE (info) ON `team`.`player` TO 'account1'@'localhost' |

3.5
revoke all on team.player from account1@'localhost';//撤权

3.6
drop user account1;

你可能感兴趣的:(mysql,adb,android)