分类 数据库 下的文章

远程访问mysql

用root登录mysql
mysql -u root -p
use mysql;
grant all privileges on . to username@"%" identified by 'password' with grant option;
exit;

sudo vi /etc/mysql/my.cnf
注释掉bind-address = 127.0.0.1
也有sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

sudo service mysql restart

搞定!

create user 'user'@'%' identified by '******';
create database db_name DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
grant all privileges on db_name.* to 'user'@'%' identified by '******';
flush privileges;
插入中文乱码,连接字符串+Charset=utf8;

用mysql记录传感器数据

首先是要建立一个数据库,我们命名为iot,选择utf8_unicode_ci;
然后是建立表,t_data

DROP TABLE IF EXISTS `t_data`;
CREATE TABLE `t_data` (
  `id` BIGINT NOT NULL AUTO_INCREMENT,
  `sid` int NOT NULL,
  `svalue` varchar(50) NOT NULL,
  `sdatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
)

尝试插入数据

INSERT INTO `iot`.`t_data` (`sid`, `svalue`) VALUES ('3', '26.5');

参考文献:大球的《香蕉派正确吃法之物联网–把数据写到数据库