Databases

gain a good understand of both SQL & noSQL

MySQL

Install

default directory on Linux /var/lib/mysql

wget https://...mysql.rpm

# install by yum or RPM
sudo yum install mysql-server
# or
sudo yum install https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
sudo yum install mysql-community-server

# start service
serivce mysqld start

# check the status
service mysqld status

# validate and get the temporary password
cat /var/log/mysqld.log
Restart
# ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
mysql.server restart
Login
# validate and get the temporary password
cat /var/log/mysqld.log
sudo grep 'temporary password' /var/log/mysqld.log

# login to mysql server by temporary password
mysql -u [user] -p [password]
mysql -u root -p'PrYJ0.g(OStY'

# check password policy
mysql> SHOW VARIABLES LIKE 'validate_password%';
User
# change the default user's password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpass17!';

# create new user
mysql> CREATE USER 'phuong'@'localhost' IDENTIFIED BY 'newpass17!';

# if you want a user to connect to all system, do not specify the host
mysql> CREATE USER 'phuong'@'%' IDENTIFIED BY 'newpass17!';
Privileges
# grant permission
mysql> GRANT [permission] ON [DB.table] TO 'phuong'@'%';

# show granted permission
mysql> SHOW GRANTS FOR 'phuong'@'hostname';

MongoDB

Structure

Install
# install by yum
yum install mongodb-org

# check log
cat /var/log/mongodb/mongod.log
Configuration

The configuration file located at /etc/mongod.conf

Last updated