允许所有用户远程登录:
grant all on *.* to 'root'@'%' identified by '123456';
grant all privileges on DBName.* to USERname@'%' identified by '123456';
需要刷新权限表
flush privileges;
显示数据库中所有的表:
show Tables;
显示索引信息:
show index from Table_name;
显示表数据:
select * from Table_name;
显示表中指定行数:
select * from Table_Name limit 10;
修复表:
repair table Table_name
更新表:
update 表名 set name=?,password=?.... where id=?
增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MYSQL,然后键入以下命令:
grant select,insert,update,delete on *.* to test2@localhost identified by "abc";
如果你不想test2有密码,可以再打一个命令将密码消掉。
grant select,insert,update,delete on mydb.* to test2@localhost identified by "";
建立一个用户,并赋予远程连接权限:grant all on db.* to Name identified by 'password'
导入sql脚本
mysql -u 用户名 -p 数据库名 < 存放位置
mysqljump -u root -p test < c:/a.sql
注意,test数据库必须已经存在
limit:
limit是mysql的语法
select * from table limit m,n
其中m是指记录开始的index,从0开始,表示第一条记录
n是指从第m+1条开始,取n条。
select * from tablename limit 2,4
即取出第3条至第6条,4条记录
如果想指定部分权限给一用户,可以这样来写:
mysql>grant select,update on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系统权限表。
mysql>flush privileges;
3.删除用户。
>mysql -u root -p
>密码
mysql>DELETE FROM user WHERE User="phplamp" and Host="localhost";
mysql>flush privileges;
//删除用户的数据库
mysql>drop database phplampDB;
4.修改指定用户密码。
@>mysql -u root -p
@>密码
mysql>update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost";
mysql>flush privileges;
mysql> show variables like '%connection%';
+--------------------------+-----------------+
| Variable_name | Value |
+--------------------------+-----------------+
| character_set_connection | utf8 |
| collation_connection | utf8_general_ci |
| max_connections | 2000 |
| max_user_connections | 0 |
+--------------------------+-----------------+
4 rows in set (0.00 sec)
mysql> show global status like '%Max_used%';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| Max_used_connections | 237 |
+----------------------+-------+
1 row in set (0.00 sec)
mysql> show processlist;
+--------+------+-----------+------------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+------+-----------+------------+---------+------+-------+------------------+
| 300717 | root | localhost | loldbrtmp8 | Query | 0 | NULL | show processlist |
+--------+------+-----------+------------+---------+------+-------+------------------+
1 row in set (0.00 sec)
===========================================================================================
#查看mysql日志设置情况
show variables like 'log%';
- 创建在线峰值表 [acc_db].[acc_maxlinelog]
CREATE TABLE `acc_maxlinelog` (
`logid` int(4) UNSIGNED NOT NULL AUTO_INCREMENT ,
`time` int(4) UNSIGNED NOT NULL ,
`count_online` int(4) UNSIGNED NOT NULL ,
`line` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
PRIMARY KEY (`logid`),
INDEX `servertime` (`time`, `line`) USING BTREE ,
INDEX `time` (`time`) USING BTREE
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=1
ROW_FORMAT=COMPACT
;
你要看某个表用了什么引擎(在显示结果里参数engine后面的就表示该表当前用的存储引擎):
mysql> show create table 表名;
update account set platform='GZ' where platform='mlds';
新建一个字段id 表示文章号用来唯一标识文章 类型是整形 ,每个字段是一列
id int indentity(1,1) ,
新建一个字段title 表示文章标题 类型是字符型 长度是100
title varchar(100),
新建一个字段 表示文章内容
[content] text
查找article1表
select * from Article1
插入一行
insert into Article1 values(1,'中国暂停进口美国“吉普牧马人”越野车','中国国家质检总局8日晚20时发布公告:暂停进口美国三大车企之一克莱斯勒“吉普牧马人”越野车。' )
insert into Article1 values(2,'中国暂停进口美国“吉普牧马人”越野车','中国国家质检总局8日晚20时发布公告:暂停进口美国三大车企之一克莱斯勒“吉普牧马人”越野车。' )
select * from Article1
update Article1 set title='abc' where id=2
delete from Article1 where id =1
select * from Article1 where title like ’%'a'%’
select count (*) from Article1
select * from t2 where title= 'abc'
select sum(id) from Article1
select avg(id) as avgvalue from Article1
select max(id) as maxvalue from Article1
select min(id) as minvalue from Article1
select * from Article1 where title<>'abc'
mysql查询某表的行数
select count(*) from tablename;
select I.*,U.tablename1 from tablename2 I INNER JOIN users U ON U.id=I.userid;