步驟 1:安裝 InfluxDB
你可以從?InfluxDB?的?InfluxDB官網(wǎng)winndows二進制安裝包下載適用于不同操作系統(tǒng)的?InfluxDB?安裝包。在本教程中,我們將介紹在?Windows上安裝?InfluxDB?的步驟。
如果所示,可以點擊下載windows版本的安卓版,右上角還可以切換其他版本的安裝包。
下載后解壓,里面有個influxd.exe啟動程序,influx2.7 服務端和客戶端已經(jīng)分離,需要客戶端的要另外下載,就在上面網(wǎng)頁的下方。
注意:influxd.exe是服務端,influx.exe是客戶端,老版本的壓縮包,兩個程序是在一塊的!?
2.7這個版本沒辦法,雙擊exe程序啟動,只能用cmd或者power 啟動influxdb 程序,命令如下:
?如上圖所示,就是代碼啟動成功了,默認端口是8086。
瀏覽器輸入http://127.0.0.1:8086?
即可訪問influxdb的web端管理界面。剛開始時,會讓你注冊用戶和密碼、組織名稱和桶名,由于本人已經(jīng)注冊過了,就不展示注冊界面了。
如果你不想用web界面操作創(chuàng)建用戶密碼和數(shù)據(jù)庫的話,也可以通過influxdb客戶端程序,通過命令創(chuàng)建。
步驟 2:使用?InfluxDB?
influxdb的一些常用命令:
進入數(shù)據(jù)庫命令行顯示所有數(shù)據(jù)庫
influx -username admin -password '123456'
數(shù)據(jù)庫管理?
顯示所有數(shù)據(jù)庫
show databases
創(chuàng)建數(shù)據(jù)庫
create database mydb
切換數(shù)據(jù)庫
use database mydb
?刪除數(shù)據(jù)庫
?drop database
數(shù)據(jù)表管理
顯示所有表
show measurements
??刪除表
drop measurement tablename
用戶管理
可以直接在web管理頁面操作,也可以命令行操作。下面以用戶admin為例介紹:
顯示用戶
SHOW users
創(chuàng)建普通用戶
CREATE USER "admin" WITH PASSWORD '123456'
?修改用戶密碼
SET PASSWORD FOR "admin" = '111111'
為普通用戶賦管理員權(quán)限
GRANT ALL PRIVILEGES TO "admin"
?查看用戶擁有的權(quán)限
SHOW GRANTS FOR "admin"
撤銷普通用戶的管理員權(quán)限
REVOKE ALL PRIVILEGES FROM "admin"
給用戶賦數(shù)據(jù)庫mydb的只讀權(quán)限
GRANT READ ON "mydb" TO "admin"
?取消用戶對數(shù)據(jù)庫mydb的寫權(quán)限
REVOKE WRITE ON "mydb" FROM "admin"
直接創(chuàng)建管理員權(quán)限用戶
CREATE USER "admin" WITH PASSWORD '123456' WITH ALL PRIVILEGES
刪除用戶
drop USER "admin"
步驟 3:Springboot 整合influxdb
在Spring Boot中,我們可以使用influxdb-java庫來與InfluxDB進行集成。下面是一個簡單的示例,展示了如何使用Spring Boot和influxdb-java庫來連接和操作InfluxDB。
1.首先,需要在pom.xml文件中添加以下依賴:
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.15</version>
</dependency>
springboot集成influxdb?
<dependency>
<groupId>com.github.miwurster</groupId>
<artifactId>spring-data-influxdb</artifactId>
<version>1.8</version>
</dependency>
2.在application.properties文件中添加以下配置:
spring.influx.url=http://localhost:8086
spring.influx.username=admin
spring.influx.password=admin
spring.influx.database=mydb
3.創(chuàng)建InfluxDBTemplate bean
@Configuration
public class InfluxDbConfig {
@Autowired
private InfluxDBProperties influxDBProperties;
@Bean
public InfluxDBConnectionFactory influxDBConnectionFactory() {
return new InfluxDBConnectionFactory(influxDBProperties);
}
@Bean
public InfluxDBTemplate influxDBTemplate(@Autowired InfluxDBConnectionFactory connectionFactory) {
return new InfluxDBTemplate(connectionFactory);
}
}
4.創(chuàng)建一個實體類,用于映射InfluxDB中的數(shù)據(jù)點:
@Data
@NoArgsConstructor
@AllArgsConstructor
@Measurement(name = "temperature")
public class TemperaturePoint {
@Column(name = "time")
@TimeField
private Instant time;
@Column(name = "value")
private Double value;
@Column(name = "location")
private String location;
}
5.在代碼中使用InfluxDBTemplate來插入數(shù)據(jù)
@Autowired
private InfluxDBTemplate<TemperaturePoint> influxDBTemplate;
public void insertData(TemperaturePoint point) {
influxDBTemplate.write(point);
}
6.在代碼中使用InfluxDBTemplate來查詢數(shù)據(jù)
@Autowired
private InfluxDBTemplate<TemperaturePoint> influxDBTemplate;
public List<TemperaturePoint> queryData() {
Query query = new Query("SELECT * FROM temperature", influxDBProperties.getDatabase());
QueryResult result = influxDBTemplate.query(query);
return resultMapper.toPOJO(result, TemperaturePoint.class);
}
這樣就完成了Spring Boot和InfluxDB的集成。你可以使用InfluxDBTemplate來進行各種操作,如插入、查詢和刪除數(shù)據(jù)。
相關(guān)文章:文章來源:http://www.zghlxwxcb.cn/news/detail-477663.html
《從零開始學習InfluxDB:安裝和使用入門教程》文章來源地址http://www.zghlxwxcb.cn/news/detail-477663.html
到了這里,關(guān)于Windows下 influxdb 數(shù)據(jù)庫安裝和簡單使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!