mysql语句积累(一)

创建临时表

CREATE TABLE AAS SELECT * FROM T_STOC_HISTORY WHERE 1=0;

单表数据导入

 create table new_a as select * from a;

 insert into new_a select * from a;

数据库备份

mysqldump -h -u -p database > test.sql

mysql -h -u -p database < test.sql

数据导入

source test.sql

\. test.sql

如果一条一条地输入,很麻烦。我们可以用文本文件的方式将所有记录加入你的数据库表中。创建一个文本文件“mysql.txt”,每行包含一个记录,用定位符(tab)把值分开,并且以在CREATE TABLE语句中列出的列次序给出,例如:使用下面命令将文本文件“mytable.txt”装载到mytable表中:mysql> LOAD DATA LOCAL INFILE "mytable.txt" INTO TABLE pet;

查询数据库中所有表名

select * from information_schema.tables

查询指定数据库中指定表的所有字段名

select column_name from information_schema.columns where

table_schema=’YOURDATABASENAME’ and table_name=‘YOURTABLENAME’

创建用户

GRANT ALL PRIVILEGES ON *.* TO 'student'@'localhost' IDENTIFIED BY 'simulate' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO
'student'@'%' IDENTIFIED BY 'simulate' WITH GRANT OPTION; 

特别的权限:
ALL: 允许做任何事(和root一样)。
USAGE: 只允许登录–其它什么也不允许做。

grant all on mydb.* to NewUserName@HostName identified by “password”;
grant usage on *.* to NewUserName@HostName identified by “password”;
grant select,insert,update on mydb.* to NewUserName@HostName identified by “password”;
grant update,delete on mydb.TestTable to NewUserName@HostName identified by “password”;
grant all privileges on *.* to root@localhost
grant select,insert,delete,update,alter,create,drop on lybbs.* to NewUserName@”%” identified by “lybbs”;

 

 

 

查看运行的进程(列出每一笔联机的信息)

show processlist

查看表的创建语句

show create table tablename

 

mysql jdbc连接url 使用中文
jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=gb2312

show varlables;列出mysql的系统设定。
show tables from db_name;列出db_name中所有数据表;
show [full] columns from table_name;列出table_name中完整信息,如栏名、类型,包括字符集编码。
show index from table_name; 列出table_name中所有的索引。
show table status;;列出当前数据库中数据表的信息。
show table status from db_name;;列出当前db_name中数据表的信息。
alter table table_name engine innodb|myisam|memory ;更改表类型
explain table_name / describe table_name ; 列出table_name完整信息,如栏名、类型。
show create table table_name 显示当前表的建表语句
alter table table_name add primary key (picid) ; 向表中增加一个主键
alter table table_name add column userid int after picid 修改表结构增加一个新的字段
alter table table_name character set gb2312 改变表的编码
select user(); 显示当前用户。
select password(’root’); 显示当前用户密码
select now(); 显示当前日期
flush privileges 在不重启的情况下刷新用户权限
mysqld –default-character-set=gb2312 ;设置默认字符集为gb2312

 

 

全局管理权限:
FILE: 在MySQL服务器上读写文件。
PROCESS: 显示或杀死属于其它用户的服务线程。
RELOAD: 重载访问控制表,刷新日志等。
SHUTDOWN: 关闭MySQL服务。 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值