码迷,mamicode.com
首页 > 数据库 > 详细

mysql配置

时间:2016-03-14 01:52:03      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:mysql(慢查询)配置

# The MySQL server

[mysqld]

port            = 3306

socket          = /tmp/mysql.sock

#skip-locking                   #是否过滤掉lock

key_buffer_size = 256M           #(关键选项) 内存配置,索引快缓冲区,不是越大越好

max_allowed_packet =1M        #导入文件(备份,还原)

table_open_cache = 256        #打开表的数量

sort_buffer_size = 1M            #排序缓冲区大小(1个线程占用),根据数字量大小而定

read_buffer_size = 1M            #读时候的缓冲区

read_rnd_buffer_size =4M         #随即读

myisam_sort_buffer_size= 64M      #针对引擎

thread_cache_size = 8              #缓冲重用的限制,跟CPU核数有关

query_cache_size= 16M             #暂存内存,存放查询结果

# Try number ofCPU‘s*2 for thread_concurrency

thread_concurrency = 8                #CPU核数有关,最大并发线程数,物理CPUx2

interactive_timeout =8              #这是时间,如果空闲的连接超过8s 就会断开

wait_timeout=8                   # interactive_timeout有关,已完成的连接数与指定时间有关

long_query_time=1                               #慢查询,超过1秒记录

log_slow_queries=/data/mysql/slow.log          #慢查询日志

log-bin=mysql-bin                    #二进制日志,主从复制

server-id      = 1                     #主从复制

 

mysql里的参数:

show  variables;   #查看mysql里的参数

%    #万能匹配,和shell*类似

SHOW STATUS LIKE ‘key_read%’;   #查看比值,看看配置得是否合适

 

 

Mysql重置密码

设置root密码:mysqlamin  -uroot password  ‘自定义的密码’ 

忘记密码在/etc/my.cnf[mysqld的底下加入skip-grant(不用密码),保存后退出重启mysql,在通过mysql  -uroot进入

use mysql;

update user set   password=password(‘新密码’) where user=’root’

select * from  user  where  user=’root’\G;     #查看root的信息

重置完密码后注释或删除skip-grant,再重启mysql服务

普通用户改密码:
update user set password=password(‘
新密码‘) where user=‘用户名‘;

 

mysql远程连接:

mysql -uroot  -h远端ip -P3306  -p密码    #客户端连接远端服务器

ERROR 1130 (HY000):Host ‘远端ip’ is not allowed to connect to this MySQLserver

telnet  远端ip  3306

提示连通了,但Host ‘远端ip’ is not allowed to connect to this MySQL  serverConnection closed by foreign host.

但可以远端连接127.0.0.1mysql  -uroot  -h127.0.0.1 -P3306  -p密码

授权:grant  all on  *.* to ‘root’@’客户端ip’identified by ‘客户端连接的密码’;     #登陆到远程服务器,授权客户端Ip登陆

取消授权:revoke all on *.* from ‘root‘@‘192.168.1.12‘ identified by ‘123‘;

      或:revoke all on *.* from ‘root‘@‘192.168.1.12‘

mysql>delete from mysql.user where host=‘192.168.0.168‘ and user=‘root‘;
flush privileges

select user,host from mysql.user;  show grants for ‘user‘@‘host‘;这两句话看权限就行了

 

Select  *from user where host=’客户端ip’\G;    #显示整齐

all   #所有权限

*.*   #第一个*是库;第二个*是表

\G   #将表的内容整齐的显示

登录到远程mysql,用selectuser();命令来查看当前登陆的用户

 

本地有多个mysql

mysql  -uroot  -S /tmp/mysql.sock  –p密码       #使用sock来登陆

 

操作:(----------------字段)

use 数据库;

create  table tb1 (`id` int(4), `name` char(40)) ENGINE=MyIASM DEFAULT CHARSET=gbk;  #创建表和表的选项,引擎为MyISAM, 默认字符集为gbk

show databases;     #查看有哪些数据库

create  database  aaa; #创建库

在库插入到表里的数据: insertinto tb1 values(1,‘aaa‘);    #由于(`id` int(4), `name` char(40))两个字段

继续插入到表里的数据: insertinto tb1 values(2,‘linux‘);

mysql> insert into tb1 (`id`) values(2);         #往表里单独插入一个数据,id2name值为NULL

mysql> insert into tb1 (`name`) values(3);

mysql> update tb1 set name = ‘cao‘ where id = ‘4‘;     #id4的就更改name

select * from tb1;              # 查看表里的内容

select database();   #查看在哪个数据库下

select user();      #查看在哪个用户

select version();     #查看是哪个版本

show tables;       #查看有哪些表

desc  tb1;    #查看表里面有哪些字段

show create table tb1\G;               #查看创表的选项/语句,整齐显示

show create table pre_forum_post\G;          #帖子表,post里包含了很多创表的语句

delete from tb1 where id=‘2‘;          #删除表里的数据id2的行

truncate table abc.tb1;       #清空指定库里的表内容,库.

drop table tb1;          #删除表

drop database abc;          #删除库

 

myslq> grant all on .*  to  ‘user1’@’192.168.11.%’  identified by ‘授权的密码         #.*是所有,to后面跟用户名,%是通配,是所有

flush privileges;     #刷新权限

show processlist;    #查看当前数据库有哪些队列

show variables;    #查看所有的变量

set  globalmax_connetion=200         #默认是150,改为200(只是临时更改,需要永久生效:修改my.cnf里的配置

show variables line ‘max_connections’;   #shellgrep的过滤意思差不多

show variables line ‘max_connec%’;        #查看max_connec开头的变量

show status;     #查看所有状态,用在调优比较多

show status like ‘%running’;    #查看以匹配running结尾

show status like ‘%buffer%’;    #查看匹配中间为buffer

 

mysql错误日志:/etc/init.d/mysqld里的datadir定义的路径,有以本地hostname.err

修复表的命令:repairtable wsw123.pre_forum_post;   #wsw123是库,pre_forum_post是表名

 

备份:

mysqldump  -p密码 库名 > /test/discuz.sql                  #备份整个论坛的库

mysqldump -uroot –p12345 wsw123 pre_forum_post > /test/post.sql    #备份论坛的库里的表

恢复:

mysql  -uroot –p密码  -D 库名 < /test/discus.sql

mysql  -uroot –p密码  -D 库名 </test/post.sql          #恢复时候不用加表名,直接库名就好

特殊备份:

备份字符集,mysqldump-uroot --default-character-set=gbk  -p12345wsw123  pre_forum_post >/test/post.sql  #防止乱码

还原字符集,mysql  -uroot --default-character-set=gbk  -p密码  -D 库名 </test/post.sql

字符集兼容性较好是utf8

 

查看日志:

因为mysql的日志是二进制,所以要用mysqlbinlog命令来查看


本文出自 “Steven一直不放弃” 博客,请务必保留此出处http://wsw26.blog.51cto.com/1442148/1750702

mysql配置

标签:mysql(慢查询)配置

原文地址:http://wsw26.blog.51cto.com/1442148/1750702

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!