1.创建数据库:
mysql> create database test ; // 在mysql里面创建数据库,数据库的ID是test。[root@host] # mysqladmin -u root -p create test ; // 在linux下创建数据库,数据库的ID是test。mysql> drop database test ; // 在mysql里面删除数据库,数据库的ID是test。[root@host] # mysqladmin -u root -p drop test ; //在linux下删除数据库,数据库的ID是test。root@host# mysql -u root -p Enter password:*******mysql> use RUNOOB; //选择数据库Database changedmysql> CREATE TABLE runoob_tbl( //数据表的名字是runoob_tbl -> runoob_id INT NOT NULL AUTO_INCREMENT, -> runoob_title VARCHAR(100) NOT NULL, -> runoob_author VARCHAR(40) NOT NULL, -> submission_date DATE, -> PRIMARY KEY ( runoob_id ) -> )ENGINE=InnoDB DEFAULT CHARSET=utf8;Query OK, 0 rows affected (0.16 sec) //root@host# mysql -u root -pEnter password:*******mysql> use RUNOOB;Database changedmysql> DROP TABLE runoob_tbl //删除数据表 runoob_tblQuery OK, 0 rows affected (0.8 sec)select * from runoob_tbl ; //查询表 runoob_tblselect ip,username from runoob_tbl ; //查询runoob_tbl表中ip和username字段select ip from runoob_tbl where username="woniu" ; //在runoob_tbl表中查询字段username=“woniu”的ipselect ip from runoob_tbl where username="woniu" order by ip desc ; //在runoob_tbl表中查询字段username=“woniu”的ip,按照ip倒序show databases; //显示所有的库 use test; //选择数据库,库的ID是testshow tables; //显示库中所有的表,要先use 选中数据库show create table runoob_tbl; //查看表结构 show index from //显示数据表的详细索引信息,包括PRIMARY KEY(主键)。quit/exit //退出mysqlmysql> select * from runoob_tbl where username like ‘%wugui‘; //在 runoob_tbl 表中获取 runoob_author 字段中以 wugui为结尾的的所有记录‘%a‘ //以a结尾的数据‘a%‘ //以a开头的数据‘%a%‘ //含有a的数据查询以 mysql字段开头的信息。SELECT * FROM runoob_tbl WHERE name LIKE ‘mysql%‘;查询包含 mysql字段的信息。SELECT * FROM runoob_tbl WHERE name LIKE ‘%mysql%‘;查询以 mysql字段结尾的信息。SELECT * FROM runoob_tbl WHERE name LIKE ‘%mysql‘;insert into warn_message(username,strength,ip,port,clienttype,logtime,country,warn_type) select username,strength,ip,port,clienttype,logtime,country,warn_type from warn_message;alter table 表名 convert to character set utf8(latin1);truncate table 表名