打开 /etc/mysql/mysql.conf.d/mysqld.cnf 添加:
character_set_server = utf8
打开 /etc/mysql/conf.d/mysql.cnf 添加:
[mysql]
default-character-set = utf8
[client]
default-character-set = utf8
重启mysql服务
service mysql restart
进入mysql检查, 如下所示则表示改好了
mysql> show variables like 'collation%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
这样修改为utf8后,如果遇到生僻汉字(utf8编码后4个字节)还是会有问题,比如“𡋾”字,插入数据库就会报错。怎么解决这种问题呢?
SQL_URI = 'mysql+mysqldb://%s:%s@%s' % (DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_HOST)
app.config['SQLALCHEMY_DATABASE_URI'] = SQL_URI + '/%s?charset=utf8mb4' % DATABASE
conn.execute("CREATE DATABASE IF NOT EXISTS %s CHARACTER SET = 'utf8mb4';" % DATABASE)
今天搞了个腾讯云服务器,发现pip安装包的时候死慢死慢,后来发现是pipy源在国外导致的, 搜了搜国内的源并没有找到靠谱的。 突然灵光一闪,打开我的阿里云服务器,发现了阿里的pipy源,于是就抄了过来。。。
cd ~
mkdir .pip
cd .pip
touch pip.conf
# 然后写入下面内容,保存退出,速度嗷嗷快!
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
上拉加载更多功能我们经常会用到,这里介绍一种极简的实现方式。
思路: 监听某一个div是否在可视区域,如果在可视区域则调用加载更多函数。
HTML CODE:
<body>
<div id="content-parent"></div>
<div><p id="loadmore">努力加载中...</p></div>
</body>
JS CODE:
var AJAX_LOAD_STEP = 6; //每次请求步长
var is_loading = false; //是否正在请求数据
var start_index = 0; //请求起始id
var has_more_item = true; //是否还有更多的数据
$(document).ready(function () {
$(window).scroll(function () {
if (!has_more_item) {
return;
}
if (is_loading) {
return;
}
var a = document.getElementById("loadmore").offsetTop;
var wst = $(window).scrollTop();
if (a >= wst && a < (wst + $(window).height())) {
setTimeout(function () {
ajax_get(start_index);
}, 300);
}
});
// 第一次请求数据
ajax_get(0);
});
function ajax_get(start) {
is_loading = true;
$.ajax({
url: '/getitem',
type: 'POST',
dataType: 'json',
async: false,
data: {
step: AJAX_LOAD_STEP,
startindex: start
},
success: function (res) {
is_loading = false;
start_index += AJAX_LOAD_STEP;
switch (res.status) {
case -1:
alert("failed:" + res.errmsg);
break;
case 0:
if (res.items.length < AJAX_LOAD_STEP) {
has_more_item = false;
$("#loadmore")[0].innerHTML = "没有更多文章了...";
}
var html_str = ""; //根据res.items生成html_str
if (start_index === AJAX_LOAD_STEP) {
$("#content-parent").html(html_str);
} else {
$("#content-parent")[0].innerHTML += html_str;
}
break;
}
},
error: function (httpReq, status, exception) {
is_loading = false;
alert(status + ";" + exception);
}
}
Code:
var = 1504159185; //2017-08-31 13:59:45
// 时间戳转换为北京时间
function timestamp2timestr(timestamp) {
var date = new Date(timestamp * 1000 + 8*60*60*1000);
return date.getUTCFullYear() + "-" + fix(date.getUTCMonth() + 1, 2) + "-" + fix(date.getUTCDate(), 2);
}
// 如果代码会在其他国家跑,需要取当地时间
// 时间戳转换为本地时间
function timestamp2timestr(timestamp) {
var toffset = new Date();
var date = new Date(timestamp * 1000 - toffset.getTimezoneOffset() * 60 * 1000);
return date.getUTCFullYear() + "-" + fix(date.getUTCMonth() + 1, 2) + "-" + fix(date.getUTCDate(), 2);
}
Code:
<html>
<head>
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div>
<input type="radio" checked="checked" onclick="click_radio()">1</input>
<input type="radio" onclick="click_radio()">2</input>
<input type="radio" onclick="click_radio()">3</input>
<br>
<button id="btn1">1</button>
<button id="btn2">2</button>
<button id="btn3">3</button>
</div>
<script type="text/javascript">
$(function() {
$("#btn1").click(function() {
$("input[type='radio']").removeAttr("checked");
// 方法1,会产生一个onclick事件
$("input[type='radio']").eq(0).click();
//$("input[type='radio']").eq(0).prop('checked', true);
});
$("#btn2").click(function() {
$("input[type='radio']").removeAttr("checked");
//$("input[type='radio']").eq(1).click();
//方法2,不会产生onclick事件
$("input[type='radio']").eq(1).prop('checked', true);
});
$("#btn3").click(function() {
$("input[type='radio']").removeAttr("checked");
//$("input[type='radio']").eq(2).click();
$("input[type='radio']").eq(2).prop('checked', true);
});
});
function click_radio() {
console.log("click radio.");
}
</script>
</body>
</html>
Command Line:
0.以root用户登录mysql
mysql -uroot -p
1.随便创建一个数据库
create database test;
2.创建用户
create user user01@localhost identified by 'your_password';
3.设置权限
grant all privileges on *.* to user01@'%' identified by 'your_password';
4.刷新权限
flush privileges;
5.修改 /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 127.0.0.1 改为 bind-address = 0.0.0.0
6.重启mysql
service mysql restart
切忌安全组入方向开放3306端口。