Database¶
- DevOps engineers deploy and manage databases
- SQL databases represent data in tabular format whereas noSQL databases represent data in documents.
MySQL¶
- Open-source SQL database
- Used by FaceBook and YouTube
yum install mysql-server
- install MySQL on CentOSsystemctl start mysqld
- start the MySQL service- Logs are available at
/var/log/mysqld.log
- When
mysqld
service is started, the logs contain a temporary password required to log into the MySQL database.
- When
mysql -u root -p
- login to the DB as root user (you will be prompted to enter password)- Commands
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword'
- change the password for root userSHOW DATABASES
CREATE DATABASE Students
USE Students
- Switch to Students database (can only work on 1 database at a time)- Once a DB is selected, you can create tables, insert values in them and so on...
User Management¶
- Root users have admin access to the DB
- Create additional users -
CREATE USER 'john'@'localhost' IDENTIFIED BY 'password'
'john'@'localhost'
means that the userjohn
can connect from the local host, he will be denied access if he tries to connect from another host.'john'@'192.168.1.10'
means that the userjohn
can connect from the host with IP192.168.1.10
'john'@'%'
means that the userjohn
can connect from any host
Assigning privileges to the users
MongoDB¶
- Open-source NoSQL database
- Data is organized into documents
- Multiple documents form a collection
- Multiple collections form a database
- We can have multiple databases within a MongoDB server
- MongoDB is available as a cloud offering or as on-premises server
yum install mongodb-org
systemctl start mongod
- start the MongoDB service- Logs are stored at
/var/log/mongodb/mongod.1og
- Configuration file is available at
/etc/mongod.conf
- Commands
mongo
- activate mongo shellshow dbs
- show databasesuse school
- switch to school DB (if not present, create new and switch)
Last updated: 2022-09-24