redis的网页客户端phpRedisAdmin

1 介绍

phpRedisAdmin 是一个基于php开发的redis客户端。

https://github.com/erikdubbelboer/phpRedisAdmin

2 安装

git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git

cd phpRedisAdmin

git clone https://github.com/nrk/predis.git vendor

3 配置

如果要修改配置,则复制 config.simple.inc.php 为 config.inc.php ,然后进行修改即可;

访问 redis 数据通常要进行认证,要确保数据安全;

redis服务器设置的认证为:

//'auth' => 'redispasswordhere'

而phpRedisAdmin自身网页的认证为:

// Uncomment to enable HTTP authentication
'login' => array(
// Username => Password
// Multiple combinations can be used
'admin' => array(
'password' => 'adminpassword',
)
),

查看mysql数据库及表编码格式

1.查看数据库编码格式

1mysql> show variables like 'character_set_database';

 2.查看数据表的编码格式

1mysql> show create table <表名>;

 3.创建数据库时指定数据库的字符集

mysql>create database <数据库名> character set utf8;

4.创建数据表时指定数据表的编码格式

create table tb_books (     
name varchar(45) not null,
price double not null,
bookCount int not null,
author varchar(45) not null
)
default charset = utf8;

5.修改数据库的编码格式

mysql>alter database <数据库名> character set utf8;

6.修改数据表格编码格式

mysql>alter table <表名> character set utf8;

7.修改字段编码格式

mysql>alter table <表名> change <字段名> <字段名> <类型> character set utf8; 
mysql>alter table user change username username varchar(20) character set utf8 not null;

 8.添加外键

mysql>alter table tb_product add constraint fk_1 foreign key(factoryid) references tb_factory(factoryid); 
mysql>alter table <表名> add constraint <外键名> foreign key<字段名> REFERENCES <外表表名><字段名>;

9.删除外键

mysql>alter table tb_people drop foreign key fk_1; 
mysql>alter table <表名> drop foreign key <外键名>;

mariadb允许远程访问

ubuntu 安装的 mariadb 默认是不允许远程访问的,这里启用远程访问。

1​.修改数据库配置文件:sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf
修改内容:将配置文件中的bind-address=127.0.0.1前面加上#号注释掉。

2.修改root的远程访问权限
sudo mysql -u root -p mysql
use mysql;

update user set host='%' where user='root';
update user set password=PASSWORD("12345678") where user="root";

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '12345678' WITH GRANT OPTION;
flush privileges;

3退出后重启一下Mariadb:
sudo service mysql restart​

修改完就可以远程访问数据库了.

mysql常用到的查询语句

记录一下,不要老是问我了。

以id字段为依据,选择两个表中的字段
SELECT a.name as name, b.name as nickname FROM a, b WHERE a.id = b.id;

以id字段为依据,把b的name更新到a的name
UPDATE a,b SET a.name = b.name WHERE a.id = b.id;

删除字段内容中间的空格
UPDATE a SET name=REPLACE(name,' ','');

删除字段内容左右两边的空格
UPDATE a SET name=TRIM(BOTH ' ' FROM name);

移动mysql数据库文件夹

os: ubuntu 12.04 server 32bit
mysql-server: 5.5.35-0ubuntu0.12.04.1

1.停止mysql
sudo service mysql stop

2.复制/移动mysql数据库文件夹
sudo cp -R -p /var/lib/mysql /srv

3.修改配置文中的datadir
vi /etc/mysql/my.cnf
修改为
datadir = /srv/mysql

4.修改apparmor
修改apparmor,允许新文件夹的权限,有两个地方需要修改。
vi /etc/apparmor.d/usr.sbin.mysqld
添加下面两行
/srv/mysql/ r,
/srv/mysql/** rwk,

vi /etc/apparmor.d/abstractions/mysql
添加下面一行
/srv/mysql/mysql.sock rw,

5.重启
sudo service apparmor restart
sudo service mysql restart

mysql因连接过多出错

提示
Host 'labeyes' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'

原因
同一个ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值),导致中断的数据库连接而导致的阻塞。

解决
方法一:使用mysqladmin flush-hosts清空
也可以在数据库中执行 flush hosts; 来实现

方法二:提高允许的max_connection_errors数量:
1.进入Mysql数据库查看max_connection_errors:
show variables like 'max_%';

2.修改max_connection_errors的数量为100:
set global max_connect_errors = 100;

mysql查询重复记录

MYSQL查询重复记录的方法很多,下面就介绍几种最常用的MYSQL查询重复记录的方法。

1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断

select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录

delete from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)

3、查找表中多余的重复记录(多个字段)

select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录

delete from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1) and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录

select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1) and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)