1
This commit is contained in:
parent
4edad03e7b
commit
664c265a5f
@ -9,6 +9,8 @@ password = "keji178"
|
||||
database_name= "accountdb" + "1"
|
||||
table_name = "accounts"
|
||||
|
||||
selected_count = 0
|
||||
|
||||
|
||||
database_config = {
|
||||
'host_name' : host_name,
|
||||
@ -30,7 +32,7 @@ select_config = [
|
||||
|
||||
|
||||
def getDatabaseCursor(config):
|
||||
#print('getDatabaseCursor\n')
|
||||
#print('getDatabaseCursor')
|
||||
|
||||
db = pymysql.connect(config['host_name'],config['user_name'],config['password'],config['database_name'])
|
||||
return db.cursor()
|
||||
@ -38,12 +40,13 @@ def getDatabaseCursor(config):
|
||||
|
||||
|
||||
def getSelectInfo(min_idx,max_idx,s_config):
|
||||
#print('getSelectInfo\n')
|
||||
#print('getSelectInfo')
|
||||
|
||||
try:
|
||||
cursor = getDatabaseCursor(s_config)
|
||||
select_sql = 'select country, province, city, sex, nickname , idx, accountid \
|
||||
from accounts where idx > %s and idx <%s and accountid is not null' % (min_idx,max_idx)
|
||||
from accounts where idx > %s and idx <= %s and accountid is not null' % (min_idx,max_idx)
|
||||
#print(select_sql)
|
||||
cursor.execute(select_sql)
|
||||
ret = cursor.fetchall()
|
||||
except:
|
||||
@ -54,7 +57,7 @@ def getSelectInfo(min_idx,max_idx,s_config):
|
||||
|
||||
|
||||
def translateToMd5(translate_info):
|
||||
#print('translateTomd5\n')
|
||||
#print('translateTomd5')
|
||||
|
||||
if translate_info:
|
||||
m = hashlib.md5()
|
||||
@ -65,7 +68,7 @@ def translateToMd5(translate_info):
|
||||
|
||||
|
||||
def saveTofile(save_info,save_name):
|
||||
#print('saveTofile\n')
|
||||
#print('saveTofile')
|
||||
|
||||
if save_info and save_name :
|
||||
with open(save_name,'a') as f:
|
||||
@ -76,23 +79,27 @@ def saveTofile(save_info,save_name):
|
||||
|
||||
def buildWid(databaseName):
|
||||
|
||||
database_name = databaseName
|
||||
database_config['database_name'] = databaseName
|
||||
select_min_idx = 10000
|
||||
select_max_idx = select_min_idx + 100
|
||||
select_max_idx = select_min_idx + 10
|
||||
|
||||
finsh_flag = 1;
|
||||
select_count = 0;
|
||||
save_file_name = 'updata_wid_test.txt'
|
||||
|
||||
|
||||
while select_count < 100 and finsh_flag:
|
||||
while select_count < 1000 and finsh_flag:
|
||||
print(select_count)
|
||||
|
||||
min_idx = select_min_idx + select_count * 1000
|
||||
max_idx = select_max_idx + select_count * 1000
|
||||
min_idx = select_min_idx + select_count * 10
|
||||
max_idx = select_max_idx + select_count * 10
|
||||
|
||||
select_info = getSelectInfo(min_idx,max_idx,database_config)
|
||||
|
||||
|
||||
|
||||
if select_info:
|
||||
#print(len(select_info))
|
||||
for player_info in select_info:
|
||||
|
||||
country = player_info[0]
|
||||
@ -103,18 +110,24 @@ def buildWid(databaseName):
|
||||
idx = player_info[5]
|
||||
accountid = player_info[6]
|
||||
|
||||
nickname_string = ''
|
||||
if nickname:
|
||||
nickname_string=str(nickname,'utf-8')
|
||||
|
||||
str1 = '%s%s%s%s'%(country, province, city, sex)
|
||||
new_str = str1 + nickname_string
|
||||
md5_str = translateToMd5(new_str)
|
||||
update_sql = "UPDATE %s SET wid = '%s' where accountid = '%s';"%(table_name,md5_str,accountid)
|
||||
saveTofile(update_sql,save_file_name)
|
||||
select_count = select_count + 1
|
||||
|
||||
#selected_count += 1
|
||||
else:
|
||||
print('finsh_flag')
|
||||
finsh_flag = 0
|
||||
select_count += 1;
|
||||
|
||||
print('buidWid END!')
|
||||
return
|
||||
|
||||
|
||||
buildWid('accountdb_bk1')
|
||||
buildWid("accountdb_bk1")
|
||||
|
@ -141,14 +141,55 @@ class Mysql
|
||||
|
||||
}
|
||||
|
||||
$conn = new Mysql(array(
|
||||
function generateWid($country, $province, $city, $sex, $nickname)
|
||||
{
|
||||
try {
|
||||
$country = empty($country) ? '' : $country;
|
||||
$province = empty($province) ? '' : $province;
|
||||
$city = empty($city) ? '' : $city;
|
||||
$sex = empty($sex) ? '0' : $sex;
|
||||
$nickname = empty($nickname) ? '' : $nickname;
|
||||
$wid = md5(
|
||||
$country . $province . $city . $sex . $nickname
|
||||
);
|
||||
return $wid;
|
||||
} catch (Exception $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
for ($i = 1; $i <= 20; ++$i) {
|
||||
|
||||
$conn = new Mysql(array(
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 3306,
|
||||
'user' => 'root',
|
||||
'passwd' => 'keji178',
|
||||
'dbname' => 'accountdb_bk1',
|
||||
));
|
||||
'dbname' => 'accountdb_bk' . $i,
|
||||
));
|
||||
|
||||
$row = $conn->execQueryOne('SELECT * FROM accounts LIMIT 1, 10');
|
||||
var_dump($row);
|
||||
echo "hello world!\n";
|
||||
$start = 0;
|
||||
do {
|
||||
$rows = $conn->execQuery("SELECT * FROM accounts LIMIT $start, 10000;");
|
||||
if (empty($rows)) {
|
||||
break;
|
||||
}
|
||||
$start += count($rows);
|
||||
$total += count($rows);
|
||||
foreach ($rows as &$row) {
|
||||
// echo $row['wid'] . "\n";
|
||||
$wid = generateWid(
|
||||
$row['country'],
|
||||
$row['province'],
|
||||
$row['city'],
|
||||
$row['sex'],
|
||||
$row['nickname']
|
||||
);
|
||||
echo $wid . "\n";
|
||||
}
|
||||
} while (true);
|
||||
|
||||
echo $i . "\n";
|
||||
}
|
||||
echo $total . "\n";
|
||||
|
Loading…
x
Reference in New Issue
Block a user