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

mysql问题汇总

2016-05-17 17:50 375 查看

1、Slave_SQL_Running:No

原因:

1.程序可能在slave上进行了写操作

2.也可能是slave机器重起后,事务回滚造成的.

解决办法一:

mysql> slave stop;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> slave start;

解决办法二:

首先停掉Slave服务:slave stop
到主服务器上查看主机状态:
记录File和Position对应的值

进入master

mysql> show master status;
+----------------------+----------+--------------+------------------+
| File                 | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------------+----------+--------------+------------------+
| localhost-bin.000094 | 33622483 |              |                  | 
+----------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

 

然后到slave服务器上执行手动同步:


mysql> change master to 
> master_host='master_ip',
> master_user='user', 
> master_password='pwd', 
> master_port=3306, 
> master_log_file=localhost-bin.000094', 
> master_log_pos=33622483 ;
1 row in set (0.00 sec)
mysql> slave start;
1 row in set (0.00 sec)

 

mysql> show slave status\G
*************************** 1. row ***************************
........
            Master_Log_File: localhost-bin.000094
        Read_Master_Log_Pos: 33768775
             Relay_Log_File: localhost-relay-bin.000537
              Relay_Log_Pos: 1094034
      Relay_Master_Log_File: localhost-bin.000094
           Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
            Replicate_Do_DB:

手动同步需要停止master的写操作! 

 

2、Slave failed to initialize relay log info structure from the repository

在my.cnf配置文件中添加如下项:

relay_log = /opt/mysql/logs/mysql-relay-bin

   重启mysql实例使其生效。

 

3、ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log

解决办法:

1.进入MySQL数据库默认的数据库存储目录:

/usr/local/mysql/var

这个目录根据实际情况而定,使用不同的安装方式,或是编译指定目录不同,这个目录也不一定相同,但只要找到数据库的存储目录就好。

 

2.删除以下两个文件:

master.info

relay-log.info

 

3.登陆数据库后,执行:

start slave;

返回如下信息:

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql>

这样就说明问题已经解决了。

 

4、Starting MySQL..The server quit without updating PID file

解决办法:

1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限 
解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data”  然后重新启动mysqld! 
2.可能进程里已经存在mysql进程 
解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9  进程号”杀死,然后重新启动mysqld! 
3.可能是第二次在机器上安装mysql,有残余数据影响了服务的启动。 
解决方法:去mysql的数据目录/data看看,如果存在mysql-bin.index,就赶快把它删除掉吧,它就是罪魁祸首了。
4.mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。 
解决方法:请在[mysqld]下设置这一行:datadir = /usr/local/mysql/data 
5.skip-federated字段问题 
解决方法:检查一下/etc/my.cnf文件中有没有没被注释掉的skip-federated字段,如果有就立即注释掉吧。 
6.错误日志目录不存在 
解决方法:使用“chown” “chmod”命令赋予mysql所有者及权限 
7.selinux惹的祸,如果是centos系统,默认会开启selinux 
解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。 
但是没有解决,最后直接给/usr/local/mysql/data 目录 chmod 777 -R  /usr/local/myql/data 问题解决 应该是 权限问题,不能生成localhost.localdomain.pid 文件 
8.修改了机器名,报了个 Starting MySQL..The server quit without updating PID file (/opt/mysql/data/xxx.pid). 
xxx为新的机器名。 
进入mysql/data目录发现.pid 文件发现本地的是 localhost.pid 于是重命名为xxx.pid 启动就ok了

 

5、配置文件

mysql配置文件为my.cnf,它所在位置根据安装时设定的。
当mysqld服务启动的时候,默认会按一定的顺序读取配置文件的。
1
2
3
[root@zhu2 ~]# /opt/mysql/libexec/mysqld --verbose --help
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /opt/mysql/etc/my.cnf ~/.my.cnf
可以发现,系统默认是按/etc/my.cnf-----/etc/mysql/my.cnf----/usr/local/mysql/my.cnf的顺序读取配置文件的,当有多个配置文件时,mysql会以读取到的最后一个配置文件中的参数为准。
常用的配置参数有:
1
port = 3306
mysqld服务运行时的端口号,默认为3306
1
socket = /tmp/mysql.sock
socket文件是linux/unix系统特有的,用户在该环境下的客户端连接可以不通过tcp/ip网络,而直接使用socket文件连接
1
back_log = 300
该值为设定档mysql暂时停止响应新的请求前,短时间内有多少个请求可以存在堆栈内,如果系统在短时间内有很多的连接,应该增大该值,该值最好设置小于512的整数
1
skip-networking
不在tcp/ip端口上进行监听,所有的连接都是通过本地的socket文件连接,这样可以提高安全性,确定是不能通过网络连接数据库。
1
skip-locking
避免mysql的外部锁定,增强稳定性
1
skip-name-resolve
避免mysql对外部的连接进行DNS解析,若使用此设置,那么远程主机连接时只能使用ip,而不能使用域名
1
max_connections = 3000
指定mysql服务所允许的最大连接进程数,
1
max_connect_errors = 1000
每个主机连接允许异常中断的次数,当超过该次数mysql服务器将禁止该主机的连接请求,直到mysql服务重启,或者flushhosts命令清空host的相关信息
1
table_cache = 614k
表的高速缓冲区的大小,当mysql访问一个表时,如果mysql表缓冲区还有空间,那么这个表就会被打开通放入高速缓冲区,好处是可以更快速的访问表中的内容。
如果open_tables和opened_tables的值接近该值,那么久该增加该值的大小
1
max_allowed_packet = 4M
设定在网络传输中一次可以传输消息的最大值,系统默认为1M,最大可以是1G
1
sort_buffer_size = 16M
排序缓冲区用来处理类似orderby以及groupby队列所引起的排序,系统默认大小为2M,该参数对应分配内存是每个连接独占的,若有100个连接,实际分配的排序缓冲区大小为6*100;推荐设置为6M-8M
1
join_buffer_size 8M
联合查询操作所使用的缓冲区大小。
1
thread_cache_size = 64
设置threadcache池中可以缓存连接线程的最大数量,默认为0,该值表示可以重新利用保存在缓存中线程的数量,当断开连接时若缓存中还有空间,那么客户端的线程将被放到缓存中,如果线程重新被请求,那么请求将从缓存中读取,若果缓存中是空的或者是新的请求,那么线程将被重新创建。设置规律为:1G内存设置为8,2G内存设置为16,4G以上设置为64
1
query_cache_size = 64M
指定mysql查询缓冲区的大小,用来缓冲select的结果,并在下一次同样查询的时候不再执行查询而直接返回结果,根据Qcache_lowmem_prunes的大小,来查看当前的负载是否足够高
1
query_cache_limit = 4M
只有小于该值的结果才被缓冲,放置一个极大的结果将其他所有的查询结果都覆盖
1
tmp_table_size 256M
内存临时表的大小,如果超过该值,会将临时表写入磁盘
1
default_storage_engine = MYISAM
创建表时默认使用的存储引擎
1
log-bin=mysql-bin
打开二进制日志功能
1
key_buffer_size = 384M
指定索引缓冲区的大小,内存为4G时刻设置为256M或384M
1
read_buffer_size = 8M
用来做MYISAM表全表扫描的缓冲大小
。。。。。。。。。
常用配置实例
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock
[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /opt/mysql
datadir = /opt/mysql/var
log-error = /opt/mysql/var/mysql-error.log
pid-file = /opt/mysql/var/mysql.pid
log_slave_updates = 1
log-bin = /opt/mysql/var/mysql-bin
binlog_format = mixed
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 1G
expire_logs_days = 90
key_buffer_size = 384M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
join_buffer_size = 2M
thread_cache_size = 8
query_cache_size = 32M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
thread_concurrency = 32
table_cache = 614
table_open_cache = 512
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
external-locking = FALSE
max_allowed_packet = 16M
default-storage-engine = MYISAM
thread_stack = 192k
transaction_isolation = READ-COMMITTED
tmp_table_size = 256M
max_heap_table_size = 512M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 64M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
long_query_time = 2
slow_query_log
slow_query_log_file = /opt/mysql/var/slow.log
skip-name-resolve
skip-locking
skip-networking
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M:autoextend
innodb_file_io_threads = 4
innodb_thread_aoncurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allow_packet = 64M
[mysql]
no-auto-rehash
safr-updates
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
[mysqldump]
quick
max_allow_packet = 64M
[mysql]
no-auto-rehash
safe-updates
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout

 

6、CMake Error at cmake/readline.cmake:82 (MESSAGE):
  Curses library not found.  Please install appropriate package报错

详情如下:

cmake .
-- MySQL 5.5.21
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH) 
CMake Error at cmake/readline.cmake:82 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:126 (FIND_CURSES)
  cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)
  CMakeLists.txt:256 (MYSQL_CHECK_READLINE)


-- Configuring incomplete, errors occurred!


解决办法:
# yum -y install ncurses-devel

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: