1.
(1)
mysql> create database Market; 创建数据库
mysql> use Market 使用Market数据库
(2)
mysql> create table customers(
-> c_num int(11) primary key auto_increment,
-> c_name varchar(50),
-> c_contact varchar(50),
-> c_city varchar(50),
-> c_birth datetime not null
-> ); 创建数据表customers
(3)
mysql> alter table customers
-> modify c_contact varchar(50) after c_birth;
mysql> desc customers;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| c_num | int(11) | NO | PRI | NULL | auto_increment |
| c_name | varchar(50) | YES | | NULL | |
| c_city | varchar(50) | YES | | NULL | |
| c_birth | datetime | NO | | NULL | |
| c_contact | varchar(50) | YES | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
(4)
mysql> alter table customers
-> modify c_name varchar(70);
mysql> desc customers;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| c_num | int(11) | NO | PRI | NULL | auto_increment |
| c_name | varchar(70) | YES | | NULL | |
| c_city | varchar(50) | YES | | NULL | |
| c_birth | datetime | NO | | NULL | |
| c_contact | varchar(50) | YES | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
(5)
mysql> alter table customers
-> change c_contact c_phone varchar(50);
mysql> desc customers;
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| c_num | int(11) | NO | PRI | NULL | auto_increment |
| c_name | varchar(70) | YES | | NULL | |
| c_city | varchar(50) | YES | | NULL | |
| c_birth | datetime | NO | | NULL | |
| c_phone | varchar(50) | YES | | NULL | |
+---------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
(6)
mysql> alter table customers
-> add c_gender char(1);
mysql> desc customers;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| c_num | int(11) | NO | PRI | NULL | auto_increment |
| c_name | varchar(70) | YES | | NULL | |
| c_city | varchar(50) | YES | | NULL | |
| c_birth | datetime | NO | | NULL | |
| c_phone | varchar(50) | YES | | NULL | |
| c_gender | char(1) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
(7)
mysql> alter table customers
-> rename customers_info; 或者 rename table customers to customers_info;
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_city | varchar(50) | YES | | NULL | |
| c_birth | datetime | NO | | NULL | |
| c_phone | varchar(50) | YES | | NULL | |
| c_gender | char(1) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
(8)
mysql> alter table customers_info
-> drop c_city;
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)
(9)
mysql> alter table customers_info
-> engine=myisam;
mysql> show create table customers_info \G;
*************************** 1. row ***************************
Table: customers_info
Create Table: CREATE TABLE `customers_info` (
`c_num` int(11) NOT NULL AUTO_INCREMENT,
`c_name` varchar(70) DEFAULT NULL,
`c_birth` datetime NOT NULL,
`c_phone` varchar(50) DEFAULT NULL,
`c_gender` char(1) DEFAULT NULL,
PRIMARY KEY (`c_num`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
ERROR:
No query specified
2.
(1)
mysql> create table orders(
o_num int(11) primary key auto_increment,
o_date date, c_id varchar(50),
foreign key (c_id) references cuustomers_info (c_num)
)engine=myisam; //注意存储引擎要一致,否则创建外键约束失败
mysql> desc orders;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| o_num | int(11) | NO | PRI | NULL | auto_increment |
| o_date | date | YES | | NULL | |
| c_id | varchar(50) | YES | MUL | NULL | |
+--------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
(2)
mysql> alter table orders drop foreign key c_id; 先删除外键
mysql> alter table orders drop index c_id; 再删除索引
mysql> desc orders;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| o_num | int(11) | NO | PRI | NULL | auto_increment |
| o_date | date | YES | | NULL | |
| c_id | varchar(50) | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> drop table customers_info;
mysql> show tables;
+------------------+
| Tables_in_Market |
+------------------+
| orders |
+------------------+
1 row in set (0.00 sec)
(1)
mysql> set global validate_password_policy=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_special_char_count=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 3 |
| validate_password_mixed_case_count | 0 |
| validate_password_number_count | 0 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 0 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
修改密码强度规则
mysql> create user 'accountl'@'localhost' identified by 'oldpwdl'; 创建用户
mysql> grant select,insert on Team.player to accountl@'localhost';
mysql> grant update(info) on Team.player to accountl@'localhost'; 给权限
mysql> flush privileges;
mysql> show grants for accountl@'localhost'; 查看权限
+----------------------------------------------------------------------------------+
| Grants for accountl@localhost |
+----------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'accountl'@'localhost' |
| GRANT SELECT, INSERT, UPDATE (info) ON `Team`.`player` TO 'accountl'@'localhost' |
+----------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> revoke all on Team.player from accountl@'localhost'; 移除权限
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for accountl@'localhost';
+----------------------------------------------+
| Grants for accountl@localhost |
+----------------------------------------------+
| GRANT USAGE ON *.* TO 'accountl'@'localhost' |
+----------------------------------------------+
1 row in set (0.00 sec)
mysql> drop user accountl@'localhost'; 删除用户
Query OK, 0 rows affected (0.00 sec)
mysql> select user from mysql.user;
+-----------+
| user |
+-----------+
| test |
| mysql.sys |
| root |
+-----------+
3 rows in set (0.00 sec)