# 测试数据库中建两张表,test和test_p ,他们之间的关系是test.user_id=test_p.user_id root@SH_MySQL-01 15:19: [uplooking]> use dba; Database changed root@SH_MySQL-01 15:22: [dba]> show tables; Empty set (0.00 sec)
root@SH_MySQL-01 15:22: [dba]> create table test( -> userid int(4) primary key not null auto_increment, -> username varchar(50) not null, -> userpassword varchar(32) not null, -> nowtime datetime default CURRENT_TIMESTAMP -> ); Query OK, 0 rows affected (0.04 sec)
root@SH_MySQL-01 15:22: [dba]> insert into test values (null,'er','eesss',now()); Query OK, 1 row affected (0.01 sec)
root@SH_MySQL-01 15:22: [dba]> insert into test values (null,'er','sss',now()); Query OK, 1 row affected (0.01 sec)
root@SH_MySQL-01 15:22: [dba]> insert into test values (null,'aer','sss',now()); Query OK, 1 row affected (0.00 sec)
root@SH_MySQL-01 15:22: [dba]> select * from test; +--------+----------+--------------+---------------------+ | userid | username | userpassword | nowtime | +--------+----------+--------------+---------------------+ | 1 | er | eesss | 2018-08-10 15:22:31 | | 2 | er | sss | 2018-08-10 15:22:37 | | 3 | aer | sss | 2018-08-10 15:22:43 | +--------+----------+--------------+---------------------+ 3 rows in set (0.00 sec)
root@SH_MySQL-01 15:22: [dba]> insert into test values (null,'superman','sss',now()); Query OK, 1 row affected (0.01 sec)
root@SH_MySQL-01 15:23: [dba]> insert into test values (null,'batman','sss',now()); Query OK, 1 row affected (0.00 sec)
root@SH_MySQL-01 15:23: [dba]> insert into test values (null,'supergirl','sss',now()); Query OK, 1 row affected (0.01 sec)
root@SH_MySQL-01 15:23: [dba]> select * from test; +--------+-----------+--------------+---------------------+ | userid | username | userpassword | nowtime | +--------+-----------+--------------+---------------------+ | 1 | er | eesss | 2018-08-10 15:22:31 | | 2 | er | sss | 2018-08-10 15:22:37 | | 3 | aer | sss | 2018-08-10 15:22:43 | | 4 | superman | sss | 2018-08-10 15:23:06 | | 5 | batman | sss | 2018-08-10 15:23:12 | | 6 | supergirl | sss | 2018-08-10 15:23:18 | +--------+-----------+--------------+---------------------+ 6 rows in set (0.00 sec)
root@SH_MySQL-01 15:23: [dba]> create table test_p( -> id int(4) primary key not null auto_increment, -> userid int(4) not null, -> username varchar(50) not null, -> userpassword varchar(32) not null, -> nowtime datetime default CURRENT_TIMESTAMP -> ); Query OK, 0 rows affected (0.04 sec)
root@SH_MySQL-01 15:24: [dba]> insert into test_p values (null,'3','aer','ssss',now()); Query OK, 1 row affected (0.01 sec)
root@SH_MySQL-01 15:24: [dba]> insert into test_p values (null,'5','aer','ssss',now()); Query OK, 1 row affected (0.00 sec)
root@SH_MySQL-01 15:24: [dba]> select * from test_p; +----+--------+----------+--------------+---------------------+ | id | userid | username | userpassword | nowtime | +----+--------+----------+--------------+---------------------+ | 1 | 3 | aer | ssss | 2018-08-10 15:24:25 | | 2 | 5 | aer | ssss | 2018-08-10 15:24:30 | +----+--------+----------+--------------+---------------------+ 2 rows in set (0.00 sec)
# test_1为将来存放归档数据的表,需要提前新建出来 root@SH_MySQL-01 15:24: [dba]> create table test_1( -> userid int(4) primary key not null auto_increment, -> username varchar(50) not null, -> userpassword varchar(32) not null, -> nowtime datetime default CURRENT_TIMESTAMP -> ); Query OK, 0 rows affected (0.03 sec) # test_p_1 为将来存放归档数据的表,需要提前新建 root@SH_MySQL-01 15:46: [dba]> create table test_p_1( -> id int(4) primary key not null auto_increment, -> userid int(4) not null, -> username varchar(50) not null, -> userpassword varchar(32) not null, -> nowtime datetime default CURRENT_TIMESTAMP -> ); Query OK, 0 rows affected (0.04 sec)
|