背景:辅库删除了一个用户,主库也删除了一个用户,于是出现辅库启动时候出现错误,show slave status少一个YES。
错误:2018-03-30T18:41:50.906499+08:00 10 [ERROR] Slave SQL for channel '': Error 'Can't find any matching row in the user table' on query. Default database: ''. Query: 'GRANT DELETE ON *.* TO 'mha_rep'@'10.70.%'', Error_code: 1133
跳过一次或跳过1133都可以,如下:
mysql主从复制,经常会遇到错误而导致slave端复制中断,这个时候一般就需要人工干预,跳过错误才能继续
跳过错误有两种方式:
1.跳过指定数量的事务:
mysql>slave stop;
mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1        #跳过一个事务
mysql>slave start

2.修改mysql的配置文件,通过slave_skip_errors参数来跳所有错误或指定类型的错误
vi /etc/my.cnf
[mysqld]
#slave-skip-errors=1062,1053,1146 #跳过指定error no类型的错误
#slave-skip-errors=all #跳过所有错误

来源:https://blog.csdn.net/seteor/article/details/17264633
mysql> RESET SLAVE ALL ;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave status\G
Empty set (0.00 sec)

摘自 :
执行reset slave;
mysql> stop slave;
Query OK, 0 rows affected (0.04 sec)

mysql> reset slave;
Query OK, 0 rows affected (0.02 sec)
在次执行会发现还是会有剩余配置信息
mysql> show slave status\G

最后,
执行reset slave all这个命令看看结果
mysql> reset slave all;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G
Empty set (0.00 sec)

果然没有了.reset slave执行的时候会删除master.info和relay-log.info但是同步信息会保留.要想彻底清除可以使用reset slave all.^_^,今天先到这里了.
今天在使用冷备份文件重做从库时遇到一个报错,值得研究一下。
版本:MySQL5.6.27 
一、报错现象

dba:(none)> start slave;
ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
这个时候查看error.log:

2017-07-17 16:19:02 9022 [ERROR] Failed to open the relay log './tjtx-96-67-relay-bin.017814' (relay_log_pos 172582079).
2017-07-17 16:19:02 9022 [ERROR] Could not find target log file mentioned in relay log info in the index file './tjtx135-1-95-relay-bin.index' during relay log initialization.
2017-07-17 16:19:02 9022 [ERROR] Failed to initialize the master info structure
2017-07-17 16:19:02 9022 [Note] Check error log for additional messages. You will not be able to start replication until the issue is resolved and the server restarted.
2017-07-17 16:19:02 9022 [Note] Event Scheduler: Loaded 0 events
2017-07-17 16:19:02 9022 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.6.27-log'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)
2017-07-17 16:19:06 9022 [ERROR] Slave SQL: Slave failed to initialize relay log info structure from the repository, Error_code: 1872
从报错上看,意思是启动slave时,使用repository中信息初始化relay log结构失败了。为什么失败了?原来是从tjtx135-1-95-relay-bin.index文件中找不到tjtx-96-67-relay-bin.017814文件。到这里,答案就很清楚了,由于我使用的是冷备份文件恢复的实例,在mysql库中的slave_relay_log_info表中依然保留之前relay_log的信息,所以导致启动slave报错。

那如何解决呢?先来简单的了解MySQL Relay log的基础知识:

二、MySQL Relay log介绍

在MySQL复制结构下,Slave服务器会产生三种日志文件,用来保存主库的二进制日志事件以及relay log已执行到的位置和状态。

1、relay log 文件:由IO thread线程从主库读取的二进制日志事件组成,该日志被Slave上的SQL thread线程执行,从而实现数据的复制。

2、master info log:该文件保存slave连接master的状态以及配置信息,如用户名,密码,日志执行的位置等。在5.6版本之前,都是使用master.info文件,从5.6开始,通过在my.cnf  中配置 --master-info-repository=TABLE。这些信息会被写入mysql.slave_master_info 表中,代替原来的master.info文件了。

3、relay log info log:该文件保存slave上relay log的执行位置。在5.6版本之前,都是使用relay-log.info文件,从5.6开始,通过在my.cnf中配置 --relay-log-info-repository=TABLE,使用mysql.slave_relay_log_info表代替原来的文件。每次当slave上执行start slave时,就会读取该表中的位置信息。

新版本使用表来代替原来的文件,主要为了crash-safe replication,从而大大提高从库的可靠性。为了保证意外情况下从库的可靠性,mysql.slave_master_info和mysql.slave_relay_log_info表必须为事务性的表,从5.6.6起,这些表默认使用InnoDB存储引擎。在5.6.5及之前的版本默认使用MyISAM引擎,可用下面语句进行转换:

ALTER TABLE mysql.slave_master_info ENGINE=InnoDB;
ALTER TABLE mysql.slave_relay_log_info ENGINE=InnoDB;
【注意】不要试图手工的更新、插入、删除以上两个表的内容,以免出现意料不到的问题。

三、问题解决

通过上面的报错以及relay log介绍,很容易知道由于mysql.slave_relay_log_info表中保留了以前的复制信息,导致新从库启动时无法找到对应文件,那么我们清理掉该表中的记录不就可以了。再次提醒,不要手动删该表数据,MySQL已经提供工具给我们了:reset slave:

reset slave干的那些事:

1、删除slave_master_info ,slave_relay_log_info两个表中数据;
2、删除所有relay log文件,并重新创建新的relay log文件;
3、不会改变gtid_executed 或者 gtid_purged的值
下面解决问题:


dba:(none)> reset slave;
Query OK, 0 rows affected (0.00 sec)
1
dba:(none)> change master to ......
1
2
dba:(none)> start slave;
Query OK, 0 rows affected (0.00 sec)
到这里问题解决了。
来自:https://www.cnblogs.com/mysql-dba/p/7201513.html
【经验】:以后用冷备份恢复实例后,在启动slave前,先进行reset slave清空下以前的旧信息。

【参考资料】:https://dev.mysql.com/doc/refman/5.6/en/slave-logs.html
https://dev.mysql.com/doc/refman/5.6/en/reset-slave.html
现象:

现象:
mysql: [Warning] World-writable config file '/root/.my.cnf' is ignored.
解决Ok:
chmod 644 /root/.my.cnf  就好了。

参考:http://blog.csdn.net/xeay123/article/details/44127951
interactive_timeout :连接空闲超时时间。与服务器端无交互状态的连接,直到被服务器端强制关闭而等待的时间。
    interactive_timeout和wait_timeout意义虽然相同,但是有使用对象有本质的区别。interactive_timeout针对交互式连接(比如通过mysql客户端连接数据库),wait_timeout针对非交互式连接(比如一般在PHP中使用PDO连接数据库,当然你可以设置CLIENT_INTERACTIVE选项来改变)。所谓的交互式连接,即在mysql_real_connect()函数中使用了CLIENT_INTERACTIVE选项。
wait_timeout:连接空闲超时时间。与服务器端无交互状态的连接,直到被服务器端强制关闭而等待的时间。可以认为是服务器端连接空闲的时间,空闲超过这个时间将自动关闭。

交互连接:
interactive_timeout 需在mysql_connect()设置CLIENT_INTERACTIVE选项后起作用,并被赋值为wait_timeout;  #Mysql自己的客户端mysql命令。
mysql>set global wait_timeout = 60; 对当前交互链接有效; (由于mysql的BUG所有这边必须加global)
mysql>set global interactive_timeout = 60; 对后续起的交互链接有效;


解决MySQL server has gone away
应用程序(比如PHP)长时间的执行批量的MYSQL语句。最常见的就是采集或者新旧数据转化。
解决方案:
在my.cnf文件中添加或者修改以下两个变量:
wait_timeout=2880000
interactive_timeout = 2880000
关于两个变量的具体说明可以google或者看官方手册。如果不能修改my.cnf,则可以在连接数据库的时候设置CLIENT_INTERACTIVE,比如:
sql = "set interactive_timeout=24*3600";
mysql_real_query(...)

wait_timeout过大有弊端,其体现就是MySQL里大量的SLEEP进程无法及时释放,拖累系统性能,不过也不能把这个指设置的过小,否则你可能会遭遇到“MySQL has gone away”之类的问题,通常来说,我觉得把wait_timeout设置为10是个不错的选择,但某些情况下可能也会出问题,比如说有一个CRON脚本,其中两次SQL查询的间隔时间大于10秒的话,那么这个设置就有问题了(当然,这也不是不能解决的问题,你可以在程序里时不时mysql_ping一下,以便服务器知道你还活着,重新计算wait_timeout时间)

本质:
变量wait_timeout:服务器关闭非交互连接之前等待活动的秒数。也就是说你PHP获取一次数据后作计算了,并没有释放Mysql连接句柄,而你处理完后,继续获取数据,这个中间等待的秒数。  为了防止出现这个问题,用了mysql_ping:https://mo2g.com/view/128/
问题:这个秒数,DBA一般写10秒,能否突破和Mysql的Client一样,让它的值和interactive_timeout一样呢?

From:http://www.04007.cn/article/292.html
============================================================================================
总之,Mysql的原生客户端,在设置其wait_timeout的值时不受全局的设置限制,均等于全局(/etc/my.cnf)interactive_timeout的值,而PHP则并不改变全局的值,而是里面配置wait_timeout多少,此次连接就是多少,当然,也提供了类似Mysql自带客户端的参数。
阅读全文
The MySQL server is running with the --read-only option so it cannot execute
解决办法:
mysql> set global read_only=0;
(关掉新主库的只读属性)
flush privileges;
set global read_only=1;(读写属相)
flush privileges;
出现:
The MySQL server is running with the --read-only option so it cannot execute

来自:http://www.cnblogs.com/xionghui/archive/2013/03/01/2939342.html
问题:redis-3.0.7升级到redis-3.2.10,之前的数据文件/data/redis/6379/dump.rdb 没有删除,service redis start会报错,如下:


当前版本的redis无法处理version=7的RDB格式,这才明白是兼容性问题,但这种“向前兼容”一般很难做到的。
解决办法:删除rdb文件/var/lib/redis/6379/dump.rdb,重启redis就行了。

如果能解决掉Slave没有问题,那么, 线上坏了一台Slave的Redis可以直接替换掉即可:
在RPM打包发现:redis-3.0.7(线上)升级到redis-3.2.10的旧版本的dump.rdb格式无法启动如下:
但是经测试可以做Slave同步,现在CentOS6和CentOS7均升级至和epll仓库一样版本redis-3.2.10。
背景:就是想把博文里的一些链接给批量替换一下,如:justwinit.cn 替换为jackxiang.com, 这样式的。

遇到这么个情况:
比如:
Msql里面的某个表的某个字段里面存储的是一个人的地址,有一天这个地址的里面的某个地

名变了,那么他的地址也就要变:

比如:

原来是:


现在这个成都市变为了 “天府”市···
所以,addr字段里面的所有的值,都要把成都市改为  天府市


解决方法:

sql语句:

[sql] view plain copy
update 表名 set 字段名=REPLACE (字段名,'原来的值','要修改的值')  

当然,也可以添加条件:



最后的效果:

[sql] view plain copy
number             addr  
01             四川省天府市XXXXXX街道05号  
02             四川省天府市XXXXXX街道07号  
03             四川省天府市XXXXXX街道09号  
04             四川省天府市XXXXXX街道04号  

来自:http://blog.csdn.net/yuekunge/article/details/14170055
lam是用php写的,所以使用时需要php支持很多模块,像对ldap的支持,对zip的支持。
php安装模块见http://fffo.blog.163.com/blog/static/211913068201401464238334/

1、官网下载
wget http://prdownloads.sourceforge.net/lam/ldap-account-manager-4.3.tar.bz2?download
2、解压
tar -xjf  ldap-account-manager-4.3.tar.bz2
3、直接移动到apache 根目录
mv  ldap-account-manager-4.3 /usr/local/apache/htdocs/lam
4、给它可以访问的权限
chmod 777 -R /usr/local/apache/htdocs/lam
5、进入配置目录
cd /usr/local/apache/htdocs/lam/config
6、创建主参数文件
cp config.cfg_sample config.cfg
7、创建连接ldap服务器参数文件
cp lam.conf_sample lam.conf
vim lam.conf
修改 所有的dc=1v,dc=cn
8、web访问
http://203.195.187.200/lam/templates/login.php

上面的模式是只限管理员登录模式。现在切换到用户登录模式
点击LAM配置——>编辑服务器配置文件——>默认密码是lam(可修改)——>通用设置——>安全设定

From:http://blog.csdn.net/u012461550/article/details/42608781

我的是在:
/usr/local/lam/etc/unix.conf
MySQL 5.6 警告信息 command line interface can be insecure 修复

mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.


在命令行输入密码,就会提示这些安全警告信息。
Warning: Using a password on the command line interface can be insecure.

注: mysql -u root -pPASSWORD 或 mysqldump -u root -pPASSWORD 都会输出这样的警告信息.
1、针对mysql
mysql -u root -pPASSWORD 改成mysql -u root -p 在输入密码即可.

2、mysqldump就比较麻烦了,通常都写在scripts脚本中。

解决方法:
对于 mysqldump 要如何避免出现(Warning: Using a password on the command line interface can be insecure.) 警告信息呢?

vim /etc/mysql/my.cnf
[mysqldump]
user=your_backup_user_name
password=your_backup_password

修改完配置文件后, 只需要执行mysqldump 脚本就可以了。备份脚本中不需要涉及用户名密码相关信息。

来自:http://880314.blog.51cto.com/4008847/1348413
MySQL 5.6 警告信息 command line interface can be insecure 修复

mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.


在命令行输入密码,就会提示这些安全警告信息。
Warning: Using a password on the command line interface can be insecure.

注: mysql -u root -pPASSWORD 或 mysqldump -u root -pPASSWORD 都会输出这样的警告信息.
1、针对mysql
mysql -u root -pPASSWORD 改成mysql -u root -p 在输入密码即可.

2、mysqldump就比较麻烦了,通常都写在scripts脚本中。

解决方法:
对于 mysqldump 要如何避免出现(Warning: Using a password on the command line interface can be insecure.) 警告信息呢?

vim /etc/mysql/my.cnf
[mysqldump]
user=your_backup_user_name
password=your_backup_password

修改完配置文件后, 只需要执行mysqldump 脚本就可以了。备份脚本中不需要涉及用户名密码相关信息。

来自:http://880314.blog.51cto.com/4008847/1348413
问题现象:在tail -f  /data/logs/mysql/error.log日志中出现大量的如下信息(web用的是Zabbix,设置连接超时时间为100秒):


' host: 'localhost' (Got timeout reading communication packets)
2017-02-05T15:30:19.272811+08:00 28546 [Note] Aborted connection 28546 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
2017-02-05T15:30:22.388624+08:00 28547 [Note] Aborted connection 28547 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
2017-02-05T15:30:27.119216+08:00 28554 [Note] Aborted connection 28554 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)


解决办法:
修改[root@lovebuy114 ~]# grep timeout /etc/my.cnf
interactive_timeout = 120
wait_timeout = 120
log_warnings=1 //注意,我这里原来是2。修改成1后,问题现象果然但是已经不存在了。
在命令行中可以这样修改:
mysql>set global log_warning=1;
mysql>set global interactive_timeout = 120;
mysql>set global wait_timeout = 120;
参数简要说明:
1)interactive_timeout:
参数含义:服务器关闭交互式连接前等待活动的秒数。交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端。
参数默认值:28800秒(8小时)

解决无Notice的办法:

grep timeout /etc/my.cnf     innodb_lock_wait_timeout = 60
interactive_timeout = 28800
wait_timeout = 22
grep log_warnings /etc/my.cnflog_warnings=2


From:http://blog.csdn.net/jamesyao008/article/details/45098073


修改后,无效,原因是现在是变成了Notice,不是警告:
tail -f  /data/logs/mysql/error.log
2017-02-05T15:38:19.678134+08:00 128 [Note] Aborted connection 128 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
2017-02-05T15:38:22.452504+08:00 131 [Note] Aborted connection 131 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)

当开启MySQL数据库主从时,会产生大量如mysql-bin.00000* log的文件,这会大量耗费您的硬盘空间。
mysql-bin.000001
mysql-bin.000002
mysql-bin.000003
mysql-bin.000004
mysql-bin.000005

有三种解决方法:1.关闭mysql主从,关闭binlog;2.开启mysql主从,设置expire_logs_days;3.手动清除binlog文件,> PURGE MASTER LOGS TO ‘MySQL-bin.010′;
实现:
1.关闭mysql主从,关闭binlog
# vim /etc/my.cnf  //注释掉log-bin,binlog_format # Replication Master Server (default) # binary logging is required for replication # log-bin=mysql-bin # binary logging format - mixed recommended # binlog_format=mixed
然后重启数据库
2.重启mysql,开启mysql主从,设置expire_logs_days
# vim /etc/my.cnf  //修改expire_logs_days,x是自动删除的天数,一般将x设置为短点,如10 expire_logs_days = x //二进制日志自动删除的天数。默认值为0,表示“没有自动删除”
此方法需要重启mysql,附录有关于expire_logs_days的英文说明
当然也可以不重启mysql,开启mysql主从,直接在mysql里设置expire_logs_days
> show binary logs; > show variables like '%log%'; > set global expire_logs_days = 10;
3.手动清除binlog文件
# /usr/local/mysql/bin/mysql -u root -p > PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 10 DAY); //删除10天前的MySQL binlog日志,附录2有关于PURGE MASTER LOGS手动删除用法及示例 > show master logs;
也可以重置master,删除所有binlog文件:
# /usr/local/mysql/bin/mysql -u root -p > reset master; //附录3有清除binlog时,对从mysql的影响说明
附录:
1.expire_logs_days英文说明
Where X is the number of days you’d like to keep them around. I would recommend 10, but this depends on how busy your MySQL server is and how fast these log files grow. Just make sure it is longer than the slowest slave takes to replicate the data from your master.
Just a side note: You know that you should do this anyway, but make sure you back up your mysql database. The binary log can be used to recover the database in certain situations; so having a backup ensures that if your database server does crash, you will be able to recover the data.
2.PURGE MASTER LOGS手动删除用法及示例,MASTER和BINARY是同义词
> PURGE {MASTER | BINARY} LOGS TO 'log_name' > PURGE {MASTER | BINARY} LOGS BEFORE 'date'
删除指定的日志或日期之前的日志索引中的所有二进制日志。这些日志也会从记录在日志索引文件中的清单中被删除MySQL BIN-LOG 日志,这样被给定的日志成为第一个。
实例:
> PURGE MASTER LOGS TO 'MySQL-bin.010'; //清除MySQL-bin.010日志 > PURGE MASTER LOGS BEFORE '2008-06-22 13:00:00'; //清除2008-06-22 13:00:00前binlog日志 > PURGE MASTER LOGS BEFORE DATE_SUB( NOW, INTERVAL 3 DAY); //清除3天前binlog日志BEFORE,变量的date自变量可以为'YYYY-MM-DD hh:mm:ss'格式。
3.清除binlog时,对从mysql的影响
如果您有一个活性的从属服务器,该服务器当前正在读取您正在试图删除的日志之一,则本语句不会起作用,而是会失败,并伴随一个错误。不过,如果从属服务器是休止的,并且您碰巧清理了其想要读取的日志之一,则从属服务器启动后不能复制。当从属服务器正在复制时,本语句可以安全运行。您不需要停止它们。

来自:http://m.toutiao.com/i6371662680515674625/?tt_from=copy_link&utm_campaign=client_share&app=news_article&utm_source=copy_link&iid=6966412074&utm_medium=toutiao_ios

我的这种是因为Mysql正在运行,然后又启动时会出现这个问题,直接pkill -9 mysql:

手工运行:



服务器症状:
今天网站web页面提交内容到数据库,发现出错了,一直提交不了,数找了下原因,发现数据写不进去!第一反应,重启mysql数据库,一直执行中,停止不了也启动不了,直觉告诉我磁盘满了 !用df命令查了下,果然磁盘满了,因为当时分区采用系统默认,不知道为什么不能自动扩容!以后在处理这个问题!如图所示:

[root@rekfan ~]# df
文件系统                 1K-块      已用      可用 已用% 挂载点
/dev/mapper/vg_rekfan-lv_root
51606140  47734848   1249852  100%      /
tmpfs                  1953396        88   1953308   1%           /dev/shm
/dev/sda1               495844     37062    433182   8%        /boot
/dev/mapper/vg_rekfan-lv_home
229694676    191796 217835016   1%       /home
[root@rekfan ~]#
删除了些没用的日志后,重新启动数据库还是出错。http://blog.rekfan.com/?p=186

[root@rekfan mysql]# service mysql restart
MySQL server PID file could not be found![失败]
Starting MySQL...The server quit without updating PID file (/usr/local/mysql/data/rekfan.pid).[失败]
google了下 ,问题可能的原因有多种,具体什么原因最好的办法是先查看下错误日志:

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,就赶快把它删除掉吧,它就是罪魁祸首了。本人就是使用第三条方法解决的 !http://blog.rekfan.com/?p=186

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后存盘退出重启机器试试。


来自:http://blog.rekfan.com/articles/186.html
背景:在MySQL与PostgreSQL的对比中,PG的JSON格式支持优势总是不断被拿来比较。最主要是json这种东西在做一些物联网时用php结合很有用处。
========================真实实践成功如下所示AddTime:2016-12-4==================================
CREATE TABLE json_test(  
id INT,  
person_desc TEXT  
)ENGINE INNODB;  

INSERT INTO json_test VALUES (1,'
    {  
    "programmers": [{  
        "firstName": "Brett",  
        "lastName": "McLaughlin",  
        "email": "aaaa"  
    }, {  
        "firstName": "Jason",  
        "lastName": "Hunter",  
        "email": "bbbb"  
    }, {  
        "firstName": "Elliotte",  
        "lastName": "Harold",  
        "email": "cccc"  
    }],  
    "authors": [{  
        "firstName": "Isaac",  
        "lastName": "Asimov",  
        "genre": "sciencefiction"  
    }, {  
        "firstName": "Tad",  
        "lastName": "Williams",  
        "genre": "fantasy"  
    }, {  
        "firstName": "Frank",  
        "lastName": "Peretti",  
        "genre": "christianfiction"  
    }],  
    "musicians": [{  
        "firstName": "Eric",  
        "lastName": "Clapton",  
        "instrument": "guitar"  
    }, {  
        "firstName": "Sergei",  
        "lastName": "Rachmaninoff",  
        "instrument": "piano"  
    }]  
}');  

ALTER TABLE json_test MODIFY person_desc json;  



{
    "programmers":[
        {
            "firstName":"Brett",
            "lastName":"McLaughlin",
            "email":"aaaa"
        },
        {
            "firstName":"Jason",
            "lastName":"Hunter",
            "email":"bbbb"
        },
        {
            "firstName":"Elliotte",
            "lastName":"Harold",
            "email":"cccc"
        }
    ],
    "authors":[
        {
            "firstName":"Isaac",
            "lastName":"Asimov",
            "genre":"sciencefiction"
        },
        {
            "firstName":"Tad",
            "lastName":"Williams",
            "genre":"fantasy"
        },
        {
            "firstName":"Frank",
            "lastName":"Peretti",
            "genre":"christianfiction"
        }
    ],
    "musicians":[
        {
            "firstName":"Eric",
            "lastName":"Clapton",
            "instrument":"guitar"
        },
        {
            "firstName":"Sergei",
            "lastName":"Rachmaninoff",
            "instrument":"piano"
        }
    ]
}





mysql> SELECT id,json_keys(person_desc) as "keys" FROM json_test\G
*************************** 1. row ***************************
  id: 1
keys: ["authors", "musicians", "programmers"]
1 row in set (0.00 sec)


mysql>  SELECT json_extract(AUTHORS,'$.lastName[0]') AS 'name', AUTHORS FROM  
    ->     (  
    ->     SELECT id,json_extract(person_desc,'$.authors[0][0]') AS "authors" FROM json_test  
    ->     UNION ALL  
    ->     SELECT id,json_extract(person_desc,'$.authors[1][0]') AS "authors" FROM json_test  
    ->     UNION ALL  
    ->     SELECT id,json_extract(person_desc,'$.authors[2][0]') AS "authors" FROM json_test  
    ->     ) AS T1  
    ->     ORDER BY NAME DESC;
+------------+----------------------------------------------------------------------------+
| name       | AUTHORS                                                                    |
+------------+----------------------------------------------------------------------------+
| "Williams" | {"genre": "fantasy", "lastName": "Williams", "firstName": "Tad"}           |
| "Peretti"  | {"genre": "christianfiction", "lastName": "Peretti", "firstName": "Frank"} |
| "Asimov"   | {"genre": "sciencefiction", "lastName": "Asimov", "firstName": "Isaac"}    |
+------------+----------------------------------------------------------------------------+
3 rows in set (0.00 sec)



mysql> SELECT  
    -> json_extract(AUTHORS,'$.firstName[0]') AS "firstname",  
    -> json_extract(AUTHORS,'$.lastName[0]') AS "lastname",  
    -> json_extract(AUTHORS,'$.genre[0]') AS "genre"  
    -> FROM  
    -> (  
    -> SELECT id,json_extract(person_desc,'$.authors[0]') AS "authors" FROM json_test  
    -> ) AS T\G ;
*************************** 1. row ***************************
firstname: "Isaac"
lastname: "Asimov"
    genre: "sciencefiction"
1 row in set (0.00 sec)

修改的方法,注意加双引号:
mysql> update json_test set  person_desc=json_set(person_desc,"$.authors[2].firstName",'dong');
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT id,json_extract(person_desc,'$.authors[2].firstName') AS "authors" FROM json_test;
+------+---------+
| id   | authors |
+------+---------+
|    1 | "dong"  |
+------+---------+
1 row in set (0.00 sec)



自己设计一个Json串的字段:
  {  
    "deviceinfo": [{  
        "chineseName": "蛋壳孵化I型",  
        "EnglishName": "LevooAllCanBeHatch",  
        "deviceMacAdd": "00-50-56-C0-00-08"  
    }],  
    "tcpserverinfo": [{  
        "fd": "Isaac",  
        "connTime": "2014-11-11 23:45:21",  
        "connIp": "127.0.0.1"  
    }],  
    "websocketinfo": [{  
        "fd": "1",  
        "connTime": "2014-11-11 23:45:21",  
        "connIp": "127.0.0.1"  
    }, {  
        "fd": "21",  
        "connTime": "2014-11-11 23:45:21",  
        "connIp": "127.0.0.2"  
    }]  
}


mysql> update `json_test` set person_desc=json_set(person_desc, "$.deviceinfo[0].chineseName", '蛋壳108') where id=20;          
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql>  SELECT * FROM json_test where id=20\G;
*************************** 1. row ***************************
         id: 20
person_desc: {"deviceinfo": [{"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳108", "deviceMacAdd": "00-50-56-C0-00-08"}], "tcpserverinfo": [{"fd": "Isaac", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}], "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "21", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}
1 row in set (0.00 sec)




Json的格式更简单一些:
  {  
    "deviceinfo": {  
        "chineseName": "蛋壳孵化I型",  
        "EnglishName": "LevooAllCanBeHatch",  
        "deviceMacAdd": "00-50-56-C0-00-08"  
    },  
    "tcpserverinfo": {  
        "fd": "Isaac",  
        "connTime": "2014-11-11 23:45:21",  
        "connIp": "127.0.0.1"  
    },  
    "websocketinfo": [{  
        "fd": "1",  
        "connTime": "2014-11-11 23:45:21",  
        "connIp": "127.0.0.1"  
    }, {  
        "fd": "21",  
        "connTime": "2014-11-11 23:45:21",  
        "connIp": "127.0.0.2"  
    }]  
}
mysql> update `json_test` set person_desc=json_set(person_desc, "$.deviceinf.chineseName", '蛋壳108') where id=30;
Query OK, 0 rows affected (0.01 sec)
Rows matched: 1  Changed: 0  Warnings: 0


=================================================================================================================
mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳孵化I型", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "Isaac", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "21", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}
1 row in set (0.00 sec)

mysql> update `json_test` set person_desc=json_set(person_desc, "$.deviceinfo.chineseName", '蛋壳1081') where id=30;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳1081", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "Isaac", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "21", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}
1 row in set (0.00 sec)


=================================================================================================================
mysql> update `json_test` set person_desc=json_set(person_desc, "$.deviceinfo.chineseName", '蛋壳108109') where id=30;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳108109", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "Isaac", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "21", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}
1 row in set (0.00 sec)

===================================================================================================================
mysql> update `json_test` set person_desc=json_set(person_desc, "$.tcpserverinfo.fd", '蛋壳108109') where id=30;                      
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0



======================================================修改二级=====================================================
mysql> update `json_test` set person_desc=json_set(person_desc, "$.websocketinfo[1].fd", '22') where id=30;                                
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳108109", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "蛋壳108109", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "22", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}
1 row in set (0.00 sec)


=================================插入新的数组属性===================================
mysql> update `json_test` set person_desc=json_insert(person_desc, "$.websocketinfo[1].fdfd", '2222') where id=30;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳108109", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "蛋壳108109", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "22", "fdfd": "2222", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}


最后想了一下,那个websocket是没有啥用的,直接简单化即可:
{
    "deviceinfo":{
        "EnglishName":"LevooAllCanBeHatch",
        "chineseName":"蛋壳108109",
        "deviceMacAdd":"00-50-56-C0-00-08"
    },
    "tcpserverinfo":{
        "fd":"蛋壳108109",
        "connIp":"127.0.0.1",
        "connTime":"2014-11-11 23:45:21"
    },
    "websocketinfo":[
        {
            "fd":"1",
            "connIp":"127.0.0.1",
            "connTime":"2014-11-11 23:45:21"
        }
    ]
}



josn类不能有如下默认值:
{
    "deviceinfo":{
        "EnglishName":"N/A",
        "chineseName":"N/A",
        "deviceMacAdd":"N/A"
    },
    "tcpserverinfo":{
        "fd":"N/A",
        "connIp":"N/A",
        "connTime":"N/A"
    },
    "websocketinfo":[
        {
            "fd":"N/A",
            "connIp":"N/A",
            "connTime":"N/A"
        }
    ]
}



php json.php
{
    "deviceinfo":{
        "EnglishName":"N/A",
        "chineseName":"N/A",
        "deviceMacAdd":"N/A"
    },
    "tcpserverinfo":{
        "fd":"N/A",
        "connIp":"N/A",
        "connTime":"N/A"
    },
    "websocketinfo":[
        {
            "fd":"N/A",
            "connIp":"N/A",
            "connTime":"N/A"
        }
    ]
}Array
(
    [deviceinfo] => Array
        (
            [EnglishName] => N/A
            [chineseName] => N/A
            [deviceMacAdd] => N/A
        )

    [tcpserverinfo] => Array
        (
            [fd] => N/A
            [connIp] => N/A
            [connTime] => N/A
        )

    [websocketinfo] => Array
        (
            [0] => Array
                (
                    [fd] => N/A
                    [connIp] => N/A
                    [connTime] => N/A
                )

        )

)



mysql> select json_extract(data,'$.tcpserverinfo.fd') as fd from hatch_dev_temp where hatchdevid=1;
+----------------+
| fd             |
+----------------+
| "蛋壳108109"   |
+----------------+
1 row in set (0.00 sec)


=============================================================================================
mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳孵化I型", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "Isaac", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "21", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}
1 row in set (0.00 sec)

mysql> update `json_test` set person_desc=json_set(person_desc, "$.deviceinfo.chineseName", '蛋壳1081') where id=30;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳1081", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "Isaac", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "21", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}
1 row in set (0.00 sec)


=============================================================================================
mysql> update `json_test` set person_desc=json_set(person_desc, "$.deviceinfo.chineseName", '蛋壳108109') where id=30;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳108109", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "Isaac", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "21", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}
1 row in set (0.00 sec)

===================================================================================================================
mysql> update `json_test` set person_desc=json_set(person_desc, "$.tcpserverinfo.fd", '蛋壳108109') where id=30;                      
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0



======================================================修改二级=====================================================
mysql> update `json_test` set person_desc=json_set(person_desc, "$.websocketinfo[1].fd", '22') where id=30;                                
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳108109", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "蛋壳108109", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "22", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}
1 row in set (0.00 sec)


=================================插入新的数组属性===================================
mysql> update `json_test` set person_desc=json_insert(person_desc, "$.websocketinfo[1].fdfd", '2222') where id=30;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM json_test where id=30\G;
*************************** 1. row ***************************
         id: 30
person_desc: {"deviceinfo": {"EnglishName": "LevooAllCanBeHatch", "chineseName": "蛋壳108109", "deviceMacAdd": "00-50-56-C0-00-08"}, "tcpserverinfo": {"fd": "蛋壳108109", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, "websocketinfo": [{"fd": "1", "connIp": "127.0.0.1", "connTime": "2014-11-11 23:45:21"}, {"fd": "22", "fdfd": "2222", "connIp": "127.0.0.2", "connTime": "2014-11-11 23:45:21"}]}


最后想了一下,那个websocket是没有啥用的,直接简单化即可:
{
    "deviceinfo":{
        "EnglishName":"LevooAllCanBeHatch",
        "chineseName":"蛋壳108109",
        "deviceMacAdd":"00-50-56-C0-00-08"
    },
    "tcpserverinfo":{
        "fd":"蛋壳108109",
        "connIp":"127.0.0.1",
        "connTime":"2014-11-11 23:45:21"
    },
    "websocketinfo":[
        {
            "fd":"1",
            "connIp":"127.0.0.1",
            "connTime":"2014-11-11 23:45:21"
        }
    ]
}



josn类不能有如下默认值:
{
    "deviceinfo":{
        "EnglishName":"N/A",
        "chineseName":"N/A",
        "deviceMacAdd":"N/A"
    },
    "tcpserverinfo":{
        "fd":"N/A",
        "connIp":"N/A",
        "connTime":"N/A"
    },
    "websocketinfo":[
        {
            "fd":"N/A",
            "connIp":"N/A",
            "connTime":"N/A"
        }
    ]
}

修改tcpserver里的fd的句柄及查询该句柄的值:
mysql> update hatch_dev_temp set data=json_set(data, "$.tcpserverinfo.fd", '108') where hatchdevid=1;                                
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select json_extract(data,'$.tcpserverinfo.fd') as fd from hatch_dev_temp where hatchdevid=1;    
+-------+
| fd    |
+-------+
| "108" |
+-------+
1 row in set (0.00 sec)

mysql> update hatch_dev_temp set data=json_set(data,"$.tcpserverinfo.fd",22) where hatchdevid=1;    
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>  select json_extract(data,'$.tcpserverinfo.fd') as fd from hatch_dev_temp where hatchdevid=1;  
+------+
| fd   |
+------+
| 22   |
+------+
1 row in set (0.00 sec)


EOF
========================================================================================


修改json数据:
JSON_SET(json_doc, path, val[, path, val] ...)
修改数据

update t set js=json_set('{"a":1,"s":"abc"}','$.a',456,'$.b','bbb') where id=1

结果js={"a":456,"s":"abc","b":"bbb"}

path中$就代表整个doc,然后可以用javascript的方式指定对象属性或者数组下标等.
执行效果,类似json的语法
$.a=456
$.b="bbb"

存在就修改,不存在就设置.

$.c.c=123
这个在javascript中会出错,因为.c为null。
但是在json_set('{}','$.c.c',123)中,不存在的路径将直接被忽略。
来自:http://blog.5ibc.net/p/36344.html
http://jackyrong.iteye.com/blog/2282003
多唯json数组的修改处理方法:
http://blog.csdn.net/yueliangdao0608/article/details/49760213


MySQL 5.7.7 labs版本开始InnoDB存储引擎已经原生支持JSON格式,该格式不是简单的BLOB类似的替换。原生的JSON格式支持有以下的优势:
JSON数据有效性检查:BLOB类型无法在数据库层做这样的约束性检查
查询性能的提升:查询不需要遍历所有字符串才能找到数据
支持索引:通过虚拟列的功能可以对JSON中的部分数据进行索引


来自:http://database.51cto.com/art/201504/472302.htm


-------------------------------------------------------------------------------------------------------------------------
MySQL 5.7原生JSON格式支持:


可以看到我们新建了表user,并且将列data定义为了JSON类型。这意味着我们可以对插入的数据做JSON格式检查,确保其符合JSON格式的约束,如插入一条不合法的JSON数据会报如下错误:
mysql> insert into user values (NULL,"test");
ERROR 3130 (22032): Invalid JSON text: "Invalid value" at position 2 in value (or column) 'test'.
此外,正如前面所说的,MySQL 5.7提供了一系列函数来高效地处理JSON字符,而不是需要遍历所有字符来查找,这不得不说是对MariaDB dynamic column的巨大改进:

当然,最令人的激动的功能应该是MySQL 5.7的虚拟列功能,通过传统的B+树索引即可实现对JSON格式部分属性的快速查询。使用方法是首先创建该虚拟列,然后在该虚拟列上创建索引:

然后可以通过添加的索引对用户名进行快速的查询,这和普通类型的列查询一样。而通过explain可以验证优化器已经选择了在虚拟列上创建的新索引:
mysql> explain select * from user where user_name='"Amy"'\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: user
   partitions: NULL
         type: ref
possible_keys: idx_username
          key: idx_username
      key_len: 131
          ref: const
         rows: 1
     filtered: 100.00
        Extra: NULL
1 row in set, 1 warning (0.00 sec)
可以发现MySQL 5.7对于JSON格式堪称完美

摘自:http://www.innomysql.net/article/15319.html



修改json地址:
mysql> set @json='["apple", {"attr": [50, true], "name": "orange"}]';
Query OK, 0 rows affected (0.00 sec)

mysql> select json_insert(@json, '$[1].attr[0]', 2, '$[2]', "pear");
+-----------------------------------------------------------+
| json_insert(@json, '$[1].attr[0]', 2, '$[2]', "pear")     |
+-----------------------------------------------------------+
| ["apple", {"attr": [50, true], "name": "orange"}, "pear"] |
+-----------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select json_replace(@json, '$[1].attr[0]', 2, '$[2]', "pear");
+--------------------------------------------------------+
| json_replace(@json, '$[1].attr[0]', 2, '$[2]', "pear") |
+--------------------------------------------------------+
| ["apple", {"attr": [2, true], "name": "orange"}]       |
+--------------------------------------------------------+
1 row in set (0.00 sec)

mysql>  select json_set(@json, '$[1].attr[0]', 2, '$[2]', "pear");
+----------------------------------------------------------+
| json_set(@json, '$[1].attr[0]', 2, '$[2]', "pear")       |
+----------------------------------------------------------+
| ["apple", {"attr": [2, true], "name": "orange"}, "pear"] |
+----------------------------------------------------------+
1 row in set (0.01 sec)

mysql> select json_remove(@json, '$[1].attr[0]', '$[2]');
+-----------------------------------------------+
| json_remove(@json, '$[1].attr[0]', '$[2]')    |
+-----------------------------------------------+
| ["apple", {"attr": [true], "name": "orange"}] |
+-----------------------------------------------+
1 row in set (0.00 sec)
在phpMyAdmin中提示“Configuration of pmadb… not OK”,如下图所示:
“Configuration of pmadb… not OK”解决办法,这个问题不大,不影响使用,仅仅是一个警告。如果不想总是看见这个警告,可以用如下办法来解决。

(1)初始化phpmyadmin数据库
cd /Library/WebServer/Documents/phpmyadmin/sql
mysql -u root -p < create_tables.sql
Enter password:

mysql> CREATE DATABASE phpmyadmin;
Query OK, 1 row affected (0.02 sec)

mysql> use phpmyadmin
Database changed
mysql> source /data/htdocs/dev.XXX.com/phpmyadmin/sql/create_tables.sql


(2)创建数据库用户
CREATE USER 'pma'@'localhost' IDENTIFIED BY 'pmapass';
GRANT ALL PRIVILEGES ON `phpmyadmin`.* TO 'pma'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;


(3)配置config.ini.php文件
vim config.inc.php
/**
* phpMyAdmin configuration storage settings.
*/

/* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = '';
// $cfg['Servers'][$i]['controlport'] = '';
// $cfg['Servers'][$i]['controluser'] = 'pma';    
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';

参考:
http://wlb.wlb.blog.163.com/blog/static/46741320158199711556/
http://bbs.vpser.net/thread-13962-1-1.html
像discuz论坛啥的, 要是楼数多,分页发现有这个问题,导致mysql的cpu负载较高,分页需要优化,如limit 222222,20,从20万以上取这样的。
再说是对mysql的INNODB引擎进行分区,以提高mysql的性能:

资料:
【分页查询时如何优化MySQL的性能?必藏】
http://toutiao.com/group/6303291874997141762/?iid=4621176401&app=news_article&tt_from=android_share&utm_medium=toutiao_android&utm_campaign=client_share

MySQL架构优化实战系列3:定时计划任务与表分区:
http://sc.qq.com/fx/u?r=BHE7tkA

MySQL架构优化实战系列2:主从复制同步与查询性能调优:
http://blog.csdn.net/huaweitman/article/details/51822082

MySQL架构优化实战系列1:数据类型与索引调优全解析:
http://udn.yyuap.com/article-11729.html
分页: 1/6 第一页 1 2 3 4 5 6 下页 最后页 [ 显示模式: 摘要 | 列表 ]