MySQL常用语句命令

修改root密码

SET PASSWORD FOR 'root'@'localhost' =PASSWORD('newpass'); 

创建数据库:

 create database cacti;

新增客户并赋予权限

grant all on cacti.* to cacti@localhostidentified by “cacti”;

刷新权限

flush privileges;

导入数据

mysql –uroot –p cacti <c:\apache\htdocs\cacti\cacti.sql

查看MySQL下用户

select * from mysql.user

 

更新的MYSQL.USER表的所有字段中为N的为Y就可以了。

>use mysql

>update user set Update_priv ='Y' whereuser = 'root';     

 

查看临时表

show variables like "%tmp%";

 

设置全局临时表大小

 setglobal tmp_table_size=33554432;

 

 

修改MySQL远程连接权限

 grant all privileges on *.* to 'root'@'%'identified by "123" with grant option;

显示当前用户权限

show grants for root@'localhost';

 

 

备份数据库

 

mysqldump -uroot -p   --database

 

 

慢查询日志分析

开启慢查询



log-slow-queries=/var/log/mysqld-slow.log

long_query_time=2

 

//dbquery-slow

query_time 查询时间

lock_time  锁表时间

rows_send  查询返回行数

rows_examind  所有查询的行数

timestamp 时间戳

查看当前数据库的表空间管理类型

show variables like"innodb_file_per_table";

innodb_file_per_table=1 为使用独占表空间

innodb_file_per_table=0 为使用共享表空间

ON代表独立表空间管理,OFF代表共享表空间管理;