0%

一般来说著名的linux系统基本上分两大类:

  1. RedHat系列:Redhat、Centos、Fedora等
  2. Debian系列:Debian、Ubuntu等 

可重复的抽奖

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
$prize_arr = [
	['title' => '500金币', 'id' => 5, 'weight' => 1],
	['title' => '免禁buff48小时体验', 'id' => 1, 'weight' => 2],
	['title' => '防偷buff48小时体验', 'id' => 2, 'weight' => 2],
	['title' => '免禁buff24小时体验', 'id' => 3, 'weight' => 3],
	['title' => '防偷buff24小时体验', 'id' => 4, 'weight' => 3],
	['title' => '100金币', 'id' => 6, 'weight' => 3],
	['title' => '50金币', 'id' => 7, 'weight' => 6],
	['title' => '5金币', 'id' => 8, 'weight' => 10],
];

function getRand($prize_arr) {
	$result = count($prize_arr)-1; // 默认数组最后用一个
	$pro_sum = array_sum(array_map('array_pop', $prize_arr)); // 拿到总数
	// $pro_sum = array_sum(array_column($prize_arr, 'weight'));  // 两个方法都ok

	foreach ($prize_arr as $key => $value) {
		$rand_num = mt_rand(1, $pro_sum);
		if ($rand_num <= $value['weight']) {
			$result = $key;
			break;
		} else {
			$pro_sum -= $value['weight']; // 说明没有抽到,减去权重,继续来
		}
	}
	return $result;
}

有个需求:选出表里重复的数据,只保留一个

需要处理的数据

having是在分组之后,对组内数据进行筛选,where 就不多说了,在分组前添加条件的

SELECT id,name,count(name) FROM idiom group by name HAVING count(name)>=2 可以看出大概519个数据都是有重复的

  1. 查看端口是否开放 netstat -an | grep 3306 3306 发现3306只对本地有效

  2. 更改mysql配置文件中的绑定地址 vim /etc/mysql/mysql.conf.d/mysqld.cnf 注销 bind-address = 127.0.0.1这一行

  3. 重启 /etc/init.d/mysql restart

创建授权

  1. 先创用户再授权
    新建用户:create user 'username'@'host' identified by 'password';
    username 为用户名
    password 为密码
    host 如果为localhost则只能本地登录,使用%为不限制
    授权: grant privileges on databasename.tablename to 'username'@'host';
    privileges 为用户的操作权限,可以是 insert,update等等, 官方权限列表

踩坑之前的代码:

1
2
3
4
5
6
7
8
9
// HTML
<a href="javascript:;" onclick="follow(123)" class="btn btn-warning btn-sm btn-flat">OK</a>
// JS
<script>
function follow(id){
  console.log($(this));
  $(this).addClass('success'); // 这个success是添加不上去的
}
</script>

填坑:如果onclick属性没有传入this对象,则在函数定义中不能使用$(this)