1,创建表格
CREATE TABLE IF NOT EXISTS `cc_cr_complain_reply` ( `reply_id` int(11) NOT NULL AUTO_INCREMENT, `reply_content` varchar(1000) NOT NULL, `complain_id` int(11) NOT NULL, `reply_time` datetime NOT NULL, `topic_id` int(11) NOT NULL, PRIMARY KEY (`reply_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
2,增加字段
alter table `test` add `test_time` datetime;
3,选择数据库
use databasename;
4,显示所有数据库
show databases;
5,显示数据表格结构
describe databasename;
6,显示数据库表格
show tables;
7,插入数据
insert into test(test_content,test_time) values('test','2014-08-14');
8,显示数据
select * from test;
9,更新数据
update `test` set `test_content` = 'testagain' where `test_id` = 3;
10,删除数据
delete from `test` where `test_id` = 1;
11, 创建数据库
create database test;
12,删除字段
alter table `test` drop `test_time`;
13,清空数据表格
truncate table `test`;
14,创建存储过程
delimiter // create procedure `test_function`(max_num int(11)) begin declare i int default 0; declare rand_num int; while i < max_num do select cast(rand()*100 as unsigned) into rand_num; insert into test_table(`number`) values(rand_num); set i = i +1; end while; end
15,查看存储过程
> show procedure status like '%test%'
16,删除存储过程
>drop procedure if exists test
17,链接数据库,默认host:localhost,port:3306
mysql --host=10.123.98.92 --user=root --password
18,获取当天日期
select curdate();
19,获取前一天日期
select date_sub(curdate(),interval 1 day)
20,获取当前时间
select now();
21,修改root用户密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password');
22,赋权给其他服务器访问
GRANT ALL PRIVILEGES ON *.* TO 'user'@'10.123.456.789' IDENTIFIED BY 'password' WITH GRANT OPTION; flush privileges;
23,查看版本信息
select VERSION(); show variables like '%version_%';
Leave a Reply