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