您的位置:首页 > 数据库 > MySQL

mysql 常用基础

2014-06-18 20:51 288 查看
登录命令 -h远程IP地址 -u用户名 -p密码 -P端口

mysql -h127.0.0.1 -uroot -p21313 -P3306

新建用户

insert into mysql.user(Host,User,Password) values("localhost","phplamp",password("1234"));

刷新权限

flush privileges;

创建数据库

create database 数据库名;

显示数据库

show databases;

切换数据库

use 数据库名;

数据库授权

grant all privileges on phplampDB.* to phplamp@localhost identified by '1234';

grant select,update on phplampDB.* to phplamp@localhost identified by '1234';

删除用户

DELETE FROM user WHERE User="phplamp" and Host="localhost";

删除数据库

drop database 数据库名;

修改用户密码

update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost";

创建定时任务

定时将A表数据统计 转存另一张表中

delimiter |
CREATE EVENT e_check06_010900 on SCHEDULE AT TIMESTAMP '2015-01-09 00:00:00'
do
begin

DROP TABLE IF EXISTS 1_accountdb.t_check_20150106_level;
CREATE TABLE IF not EXISTS 1_accountdb.t_check_20150106_level(
`level` int(11) NOT NULL,
`amount` int(11) NOT NULL,
`date` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
insert into 1_accountdb.t_check_20150106_level SELECT 1_accountdb.t_check_20150106.`level`,
count(1_accountdb.t_check_20150106.`level`) as amount,
TIMESTAMP(now()) as `date`
from t_check_20150106 group by 1_accountdb.t_check_20150106.level;
end |
delimiter;

数据库联查

select * from ( SELECT
phone_table.datetime,
phone_table.phone,
phone_table.systemtype,
count(*) as amount
FROM `phone_table` where phone_table.systemtype not like 'Intel(R)%' group by phone_table.phone ) as temp where temp.amount = 1 ORDER BY temp.systemtype;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: