电脑里安装了多种常用数据库,但是又不会经常都用到,所以没有设置开机启动,但是时间长了经常忘记启动命令,这里总结一下,以便忘记是随时查看。
一、mongoDB
1、首先开启mongo数据库服务,mongod,它需要一直在后台运行才可以保证数据库连接正常。
sudo service mongod start # 开启
2、然后就可以在终端启动mongo了,也可以用可视化工具如Robo3T连接
➜ ~ sudo service mongod start ➜ ~ mongo MongoDB shell version v3.4.18 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.18 Server has startup warnings: 2018-12-04T18:02:44.177+0800 I STORAGE [initandlisten] 2018-12-04T18:02:44.177+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 2018-12-04T18:02:44.177+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem 2018-12-04T18:02:44.993+0800 I CONTROL [initandlisten] 2018-12-04T18:02:44.993+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2018-12-04T18:02:44.994+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2018-12-04T18:02:44.994+0800 I CONTROL [initandlisten] >
3、不用的时候可以选择关闭mongo后台服务
sudo service mongod stop # 关闭
二、MySQL
1、启动MySQL服务:
sudo service mysql start # 方式一 sudo /etc/init.d/mysql start # 方式二
启动后可以看看状态:
➜ init.d service mysql status ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en Active: active (running) since 二 2018-12-04 13:55:17 CST; 4h 18min ago Process: 1112 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=ex Process: 1096 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exit Main PID: 1111 (mysqld) CGroup: /system.slice/mysql.service └─1111 /usr/sbin/mysqld 12月 04 13:55:16 zzf-ubuntu systemd[1]: Starting MySQL Community Server... 12月 04 13:55:17 zzf-ubuntu systemd[1]: Started MySQL Community Server.
2、然后就可以连接MySQL数据库了,不管是终端、命令行、程序还是可视化工具
➜ ~ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 7 Server version: 5.7.24-0ubuntu0.16.04.1 (Ubuntu) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> ^DBye
3、关闭同mongo,改成stop即可
4、另外开启时候也可以重启,使用restart命令即可。
三、Redis
1、服务启动
通过指定配置文件启动,要清楚自己的配置文件位置
redis-server /etc/redis/redis.conf
2、然后就可以通过各种方式连接redis数据库了
➜ ~ redis-cli 127.0.0.1:6379>
3、关闭Redis服务
redis-cli shutdown